水题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代码实现的多目标优化模型。该模型深度融合电-氢耦合系统与高比例波动性可再生能源(如风电、光伏),充分挖掘电动汽车(EV)集群作为移动储能单元的灵活调节潜力,通过聚合调控提升系统对新能源的消纳能力与运行经济性。研究系统构建了电动汽车可调度能力、电解制氢与储氢动态过程、多能源协同互补的优化调度框架,并结合智能优化算法实现经济性、低碳性与运行稳定性等多重目标的协同优化。文中配套提供了完整的Matlab仿真代码、相关数据及可能的论文支撑材料,极大地方便了模型的复现、验证与后续深化研究。; 适合人群:具备电力系统、综合能源系统、优化理论或新能源技术等相关领域基础知识的研究生、科研人员,以及从事新型电力系统规划、清洁能源消纳与智慧能源管理的工程技术人员。; 使用场景及目标:①开展高渗透率可再生能源接入下的综合能源系统多目标优化调度研究;②探究电动汽车集群在电网削峰填谷、平抑新能源出力波动及提供辅助服务方面的应用价值与潜力;③学习并掌握电氢耦合系统的建模方法、多目标优化求解技术及其在Matlab/Simulink环境下的仿真实现流程。; 阅读建议:此资源不仅提供可运行的代码,更蕴含了前沿的科研思路与创新方法,建议读者结合所提供的代码、数据与可能的论文文档,系统性地学习从问建模、算法设计到仿真分析的完整科研过程,并重点关注其中关于需求侧资源聚合、多能互补协同与绿色低碳运行的核心理念。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值