水题5连发:CF496B、609C、560B、500C、HDU5626

本文分享了在VJ竞赛中解决五道题目的过程与思路。涉及搜索、思维、贪心等算法,并通过具体代码示例展示了每种类型的解题方法。

半夜睡不着在VJ上挂了5道水题练手:http://vjudge.net/contest/143771#overview
A:CF496B
题目传送门:http://codeforces.com/problemset/problem/496/B
类型:搜索

#include<string>
#include<cstdio>
#include<cstring>
#include<map>
#include<queue>
#include<iostream>
using namespace std;
char str[1005];
map<string,int> m;
string ans;
string change1(string str)
{
    int len = str.length();
    for (int i = 0; i < len; i++)
    {
        if (str[i] == '9') str[i] = '0';
        else str[i] = str[i] + 1;
    }
    return str;
}
string change2(string str)
{
    int len = str.length();
    char tmp = str[len-1];
    for (int i = len-2; i >= 0; i--)
        str[i+1] = str[i];
    str[0] = tmp;
    return str;
}
void bfs(string a)
{
    queue<string> q;
    m[a] = 1;
    q.push(a);
    ans = a;
    while (!q.empty())
    {
        string s = q.front();
        q.pop();
        if (s < ans) ans = s;
        string s1 = change1(s);
        string s2 = change2(s);
        if (!m[s1])
        {
            q.push(s1);
            m[s1] = 1;
        }
        if (!m[s2])
        {
            q.push(s2);
            m[s2] = 1;
        }
    }
}
int main()
{
    int n;
    scanf("%d", &n);
    string str;
    cin >> str;
    bfs(str);
    cout << ans << endl;
    return 0;
}

B:CF609C
题目传送门:http://codeforces.com/problemset/problem/609/C
类型:思维

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 100005;
int num[maxn];
int main()
{
    int n,sum = 0,Min,Max;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &num[i]);
        sum += num[i];
    }
    if (sum % n == 0)
    {
        Min = Max = sum / n;
    }
    else
    {
        Min = sum / n;
        Max = Min + 1;
    }
    int ans1 = 0;
    int ans2 = 0;
    for (int i = 0; i < n; i++)
    {
        if (num[i] < Min)
            ans1 += Min - num[i];
        else if (num[i] > Max)
            ans2 += num[i] - Max;
    }
    printf("%d\n",max(ans1,ans2));
}

C:CF560B
题目传送门:http://codeforces.com/problemset/problem/560/B
类型:简单思维

#include<cstdio>
#include<algorithm>
using namespace std;
#define ok {puts("YES");return 0;}
int main()
{
    int a1,b1,a2,b2,a3,b3;
    scanf("%d %d %d %d %d %d", &a1, &b1, &a2, &b2, &a3, &b3);
    if (a2 + a3 <= a1 && max(b2,b3) <= b1) ok
    if (a2 + b3 <= a1 && max(b2,a3) <= b1) ok
    if (b2 + a3 <= a1 && max(a2,b3) <= b1) ok
    if (b2 + b3 <= a1 && max(a2,a3) <= b1) ok
    if (a2 + a3 <= b1 && max(b2,b3) <= a1) ok
    if (a2 + b3 <= b1 && max(b2,a3) <= a1) ok
    if (b2 + a3 <= b1 && max(a2,b3) <= a1) ok
    if (b2 + b3 <= b1 && max(a2,a3) <= a1) ok
    puts("NO");
    return 0;
}

D:CF500C
题目传送门:http://codeforces.com/problemset/problem/500/C
类型:贪心

#include<cstdio>
int w[505];
int b[1005];
bool vis[505];
int num[505];
int main()
{
    int n,m,cnt = 0,ans = 0;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &w[i]);
    for (int i = 0; i < m; i++)
    {
        scanf("%d", &b[i]);
        if (vis[b[i]] == 0)
        {
            num[cnt++] = b[i];
            vis[b[i]] = true;
        }
    }
    int j;
    for (int i = 1; i < m; i++)
    {
        for (j = 0; j < cnt; j++)
        {
            if (b[i] == num[j])
                break;
            else
                ans += w[num[j]];
        }
        for (int k = j-1; k >= 0; k--)
        {
            num[k+1] = num[k];
        }
        num[0] = b[i];
    }
    printf("%d\n",ans);
    return 0;
}

E:HDU5626
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5626
类型:简单分类讨论

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
long long seed;
inline long long rand(long long l, long long r)
{
    static long long mo = 1e9 + 7, g = 78125;
    return l + ((seed *= g) %= mo) % (r-l+1);
}
const ll INF = 1e15;
int main()
{
    int t,n;
    ll x,y,Min1,Min2,Max1,Max2;
    scanf("%d", &t);
    while (t--)
    {
 //       Min1 = Min2 = INF; //INF多次累加溢出,不要这样用
   //     Max2 = Max2 = -INF;//INF多次累加溢出,不要这样用
        scanf("%d %I64d", &n, &seed);
        x = rand(-1000000000, 1000000000);
        y = rand(-1000000000, 1000000000);
        Min1 = Max1 = x + y;
        Min2 = Max2 = x - y;
    //    printf("%I64d\n",Min1);
        for (int i = 1; i < n; i++)
        {
            x = rand(-1000000000, 1000000000),
            y = rand(-1000000000, 1000000000);
            Min1 = min(Min1,x+y);
            Min2 = min(Min2,x-y);
            Max1 = max(Max1,x+y);
            Max2 = max(Max2,x-y);
        }
        ll ans = max(Max1-Min1,Max2-Min2);
        printf("%I64d\n",ans);
    }
    return 0;
}
基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长时间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续时间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备时序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同时可扩展至不同网络结构或加入更多不确定性因素进行深化研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值