首页 > 其他分享 >Educational Codeforces Round 138 (Rated for Div. 2) ABC(二分)

Educational Codeforces Round 138 (Rated for Div. 2) ABC(二分)

时间:2022-10-21 16:15:15浏览次数:59  
标签:Educational Rated false LL cin Codeforces typedef const alice

只能说这场的出题人不适合我食用,ABC都读了假题,离谱啊~

A. Cowardly Rooks

题目大意:

给定一个棋盘n*n的大小,左下角的顶点在(1,1);

给定了棋盘格上的m个棋子坐标。这m个棋子互相不在同一个横线和竖线上;

问我们:如果一定移动其中的一个棋子,能不能保持不被攻击的原状?
input 
2
2 2
1 2
2 1
3 1
2 2
output 
NO
YES
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=1000200,M=2002;
LL a[N],b[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        for(int i=1;i<=m;i++)
        {
            cin>>a[i]>>b[i];
        }
        if(n>m) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

B. Death's Blessing

题目大意:

给定n个怪兽,每个怪兽都有生命值a[i],每次它死了之后,可以给旁边的怪兽增加b[i]点生命值。

问我们打死全部的怪兽,最少需要多少生命值?
input 
4
1
10
0
3
100 1 100
1 100 1
4
2 6 7 3
3 6 0 5
2
1000000000 1000000000
1000000000 1000000000
output 
10
203
26
3000000000

注意只需要都操作一次b[i]就行了,把最大的剩下就行。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=1000200,M=2002;
LL a[N],b[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        LL sum=0;
        for(LL i=1;i<=n;i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
        LL maxn=0;
        for(LL i=1;i<=n;i++)
        {
            cin>>b[i];
            sum+=b[i];
            maxn=max(maxn,b[i]);
        }
        cout<<sum-maxn<<endl;
    }
    return 0;
}

C. Number Game

题目大意:

给定一个长度为n的数组a,alice可以选择进行k轮游戏,每一轮(1,2,,,k)alice拿小于等于k-i+1的一个数字,然后bob相应的找数组中的一个数字添加上k-i+1,

bob不希望alice赢,但是主动权掌握在alice手中,所以alice想赢,如果在k局中alice都可以找到数字进行操作,那么就判定alice赢;

不然alice就输了,那就是bob赢。
input 
4
3
1 1 2
4
4 4 4 4
1
1
5
1 3 2 1 1
output 
2
0
1
3

这个题目的数据范围只在【1,100】之内,数据范围小,直接二分+暴力判断。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=2002;
LL n,a[N],b[N];
bool check(LL mid)
{
    LL k=mid;
    vector<LL> v;
    for(LL i=1;i<=n;i++)
    {
        if(a[i]<=k)
        {
            v.push_back(a[i]);
        }
        else break;
    }
    bool flag=true;
    for(LL i=v.size()-1,j=0;j<=i; )
    {
        while(k<v[i]&&i>0) i--;
        if(k>=v[i])
        {
            i--;
            if(i>=j)
            {
                v[j]+=k;
                j++;
            }
            k--;
        }
        else
        {
            flag=false;
            break;
        }
        if(k==0) break;
    }
    v.clear();
    if(flag==false) return false;
    else if(k==0) return true;
    else return false;
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(LL i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+1+n);
        LL l=0,r=n,maxn=0;
        while(l<=r)
        {
            LL mid=(l+r)/2;
            if(check(mid)==true)
            {
                l=mid+1;
                maxn=max(maxn,mid);
            }
            else r=mid-1;
        }
        cout<<maxn<<endl;
    }
    return 0;
}

标签:Educational,Rated,false,LL,cin,Codeforces,typedef,const,alice
From: https://www.cnblogs.com/Vivian-0918/p/16813666.html

相关文章

  • 「题解」Codeforces 1730F Almost Sorted
    给定一个长度为\(n\)的置换\(p\),以及一个正整数\(k\).对于一个置换\(q\),要求对于所有满足\(1\leqi<j\leqn\)的\(i,j\),有以下不等式成立:\[p_{q_i}\leqp_{q_j}+......
  • Codeforces Round #762 (Div. 3) E
    E.MEXandIncrements我们一看数据n个数还要计算n+1一个mex显然不能暴力我们考虑后面的i可以由前面的贪心的做一次操作转移过来所以我们记录一个a数组放着多出来的......
  • Codeforces1695 D1.+D2 Tree Queries
    题意给一个n个点的无向图,其中有一个隐藏点X,可以进行一组询问S来确定S是n个节点中的哪个点。S包括k个询问节点。询问返回的值也为k个值,每个值为X点到每个询问节点的最短路......
  • Educational Codeforces Round 138 (Rated for Div. 2)
    比赛链接EducationalCodeforcesRound138(RatedforDiv.2)D.CountingArrays解题思路容斥原理显然\([1,1,\dots,1]\)是一组方案,直接求不好求解,考虑反面,对于......
  • 论文解读(FedPCL)《Federated Learning from Pre-Trained Models: A Contrastive Learni
    论文信息论文标题:FederatedLearningfromPre-TrainedModels:AContrastiveLearningApproach论文作者:YueTan,GuodongLong,JieMa,LuLiu,TianyiZhou,JingJ......
  • Educational Codeforces Round 92 B
    B.ArrayWalk考虑dpdp[i][j]表示前i步我们撤销了j次状态转移:dp[i][j]=max{dp[i-1][j-1]+a[(i-1)-(j-1)2-1]}//我们撤销一位dp[i][j]=max{dp[i-1][j]+a[(i-1)-j2+1]}......
  • Codeforces Global Round 23-C
    C题目链接:https://codeforces.com/contest/1746/problem/C此题着实不难,就是看你自己能不能想到那种构造的方法。自己做的时候没有很好的思路,所以参考了官方的解析()。个人......
  • Educational Codeforces Round 103 C
    C.LongestSimpleCycle显然针对ab相等的话那我们就不能再往前走了所以我们考虑分为几个层我们考虑如何求出一个层的最长环我们观察这个红色的环显然我们正着做反......
  • Codeforces Round #202 (Div. 1) A. Mafia 推公式 + 二分答案
    ​​http://codeforces.com/problemset/problem/348/A​​A.MafiatimelimitpertestmemorylimitpertestinputoutputOnedaynfriendsgatheredtogethertoplay"Ma......
  • Codeforces Round #699 C
    C.FencePainting显然对于我们不同的就直接修改但是我们应该贪心的叫更后面来的人来修改这样前面的人怎么造都无所谓了for(inti=1;i<=n;i++){if(a[i]!=b[i]......