Educational Codeforces Round 104 (Rated for Div. 2) A-E 题解

71 篇文章 0 订阅

A. Arena
介绍了一下博弈的规则 我们发现只有从顺序第二个不同的数的人开始 有机会获胜 因为他可以不断找比自己积分少的人单挑

#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

#define ll long long
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) << endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) << " " << #z << " = " << (z) << endl;
const int MAX_N = 105;
int arr[MAX_N];

int main()
{
    int t,n,minn = -1,ans = n+1;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        ans = n+1;
        minn = -1;
        for(int i = 1;i<=n;++i)
        {
            scanf("%d",&arr[i]);
        }
        sort(arr+1,arr+1+n);
        for(int i = 1;i<=n;++i)
        {
            if(minn==-1) minn = arr[i];
            else if(minn==0x3f3f3f3f) continue;
            else if(arr[i]!=minn)
            {
                ans = i;
                minn = 0x3f3f3f3f;
            }
        }
        printf("%d\n",n-ans+1);
    }

    return 0;
}

B. Cat Cycle
手完一下发现 如果 n n n 是偶数 两人一定不会相遇, 否则在 n / 2 n/2 n/2步的时候 B B B 一定会因为遇到 A A A + 1 步 +1步 +1,所以我们要做的就是按照这个思路统计出 B B B的步数, + 1 步 +1步 +1的贡献在达到 n n n 次后,就会形成一个循环节

#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

#define ll long long
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) << endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) << " " << #z << " = " << (z) << endl;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ll n,m,ans;
        scanf("%lld%lld",&n,&m);
        if(n%2==0)
        {
            if(m%n==0) ans = n;
            else ans = m%n;
        }
        else
        {
            m += (m-1)/(n/2);
            if(m%n==0) ans = n;
            else ans = m%n;
        }
        printf("%lld\n",ans);
    }

    return 0;
}


C. Minimum Ties
所有胜负都是 0 0 0 平局当然是ok的 但是答案想要 0 0 0 最少
我们发现奇数的时候 一定可以没平局构造出来
偶数的时候 会多出 s u m sum sum 0 0 0 我们只要将 i < = s u m 的 i 与 i + s u m i<=sum的i 与i+sum i<=sumii+sum 构造平局即可

#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

#define ll long long
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) << endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) << " " << #z << " = " << (z) << endl;
const int MAX_N = 10025;
int ans[MAX_N],cnt[105],check[105];

int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        int len = 0;
        scanf("%d",&n);
        for(int i = 1;i<=n;++i)
        {
            cnt[i] = 0;
            check[i] = 0;
        }
        int ck = (n-1)*n/2/n;
        int sum = n*(n-1)/2 - ck * n;
        for(int i = 1;i<=n;++i)
        {
            for(int j = i+1;j<=n;++j)
            {
                if((n%2)==0&&(i<=sum)&&(j==i+sum))
                {
                    ans[++len] = 0;
                    check[i]++;
                    check[j]++;
                    continue;
                }
                if(cnt[i]<ck)
                {
                    ans[++len] = 1;
                    cnt[i]++;
                    check[i]+=3;
                }
                else if(cnt[j]<ck)
                {
                    ans[++len] = -1;
                    cnt[j]++;
                    check[j]+=3;
                }
                else
                {
                    dbg3(i,j,len);
                    ans[++len] = 0;
                    check[i]++;
                    check[j]++;
                }
            }
        }
        for(int i = 1;i<=len;++i)
        {
            i==len?printf("%d\n",ans[i]):printf("%d ",ans[i]);
        }
    }

    return 0;
}


D. Pythagorean Triples
数学题 用下勾股定理和题意给的
可以退出 a 2 = 2 ∗ b + 1 = b + c a^2 = 2*b+1 = b+c a2=2b+1=b+c
那么二分求答案即可 因为 a 2 = 2 b + 1 < 2 b + 2 < 2000000002 a^2 =2b+1 < 2b+2 <2000000002 a2=2b+1<2b+2<2000000002

#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

#define ll long long
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) << endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) << " " << #z << " = " << (z) << endl;
const int MAX_N = 500250;

int ans[MAX_N],len = 0;


void init()
{
    for(ll i = 2;1ll*i*i<=2000000001;++i)
    {
        if(1ll*i*i>2000000001) break;
        if(1ll*i*i%2==1)
        {
            if(((i*i-1)/2)<=i) continue;
            ans[++len] = (i*i-1)/2+1;
        }
    }
}

int main()
{
    init();
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        printf("%d\n",upper_bound(ans+1,ans+1+len,1ll*n)-ans-1);
    }
    return 0;
}


E. Cheap Dinner
四种类型食物 给你 1 − 2 和 2 − 3 和 3 − 4 1-2 和 2-3 和 3-4 122334 类食物互相不能共存的关系 满足条件 每个类型里选一种 使得花费最小
我们发现如果暴力跑 n ∗ n n*n nn 对于一种关系比较好做 那么 3 3 3 种关系就是 ∗ 3 *3 3 可是会超时
如果我们每次对于 i i i 食物 关注 i − 1 i-1 i1 已经拼好的最小值 我们只要 i − 1 i-1 i1 与自己可以共存 且 i − 1 i-1 i1 方案值最小即可
容易想到用 m u l t i s e t multiset multiset 去维护 但是要注意这个时间复杂度只和边有关 最差复杂度是 m ∗ l o g n m*logn mlogn 一开始自己想成了 n ∗ n ∗ l o g n n*n*logn nnlogn 绝对铁定会 T T T 还是图论做少了 以前都交给 z l s zls zls 现在自己也要重新开始了

#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
const int MAX_N = 150025;
vector<int> vt[5][MAX_N];

#define ll long long
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) << endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) << " " << #z << " = " << (z) << endl;
int N[5],arr[5][MAX_N];
ll dp[5][MAX_N];

void solve(ll dpLast[MAX_N],ll dpNow[MAX_N],int arrNow[MAX_N],int numLast,int num,vector<int> *Vt)
{
    multiset<ll> st;
    for(int i = 1;i<=num;++i) dpNow[i] = -1;
    for(int j = 1;j<=numLast;++j) if(dpLast[j]!=-1) st.insert(dpLast[j]);
    for(int i = 1;i<=num;++i)
    {
        for(auto v:Vt[i]) if(dpLast[v]!=-1) st.erase(st.find(dpLast[v]));
        if(st.empty()) dpNow[i] = -1;
        else dpNow[i] = arrNow[i] + (*st.begin());
        for(auto v:Vt[i]) if(dpLast[v]!=-1) st.insert(dpLast[v]);
    }
}
int main()
{
    int m,x,y;
    for(int i = 1;i<=4;++i) scanf("%d",&N[i]);
    for(int i = 1;i<=4;++i)
    {
        for(int j = 1;j<=N[i];++j)
        {
            scanf("%d",&arr[i][j]);
        }
    }
    for(int i = 1;i<=3;++i)
    {
        scanf("%d",&m);
        while(m--)
        {
            scanf("%d%d",&x,&y);
            vt[i+1][y].push_back(x);
        }
    }
    for(int i = 1;i<=N[1];++i) dp[1][i] = arr[1][i];
    for(int i = 1;i<=3;++i) solve(dp[i],dp[i+1],arr[i+1],N[i],N[i+1],vt[i+1]);
    ll ans = 0x3f3f3f3f3f3f3f3f;
    for(int i = 1;i<=N[4];++i) if(dp[4][i]!=-1) ans = min(ans,dp[4][i]);
    if(ans==0x3f3f3f3f3f3f3f3f) printf("-1\n");
    else printf("%lld\n",ans);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法和数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来说是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来说,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值