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

只能说这场的出题人不适合我食用,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;
}
posted @ 2022-10-21 15:59  高尔赛凡尔娟  阅读(27)  评论(0编辑  收藏  举报