Codeforces Round #808 (Div. 2) Doremy‘s IQ

题目链接:Problem - C - Codeforces

有两种情况:

第一种情况: 智商q>=n, 这种情况直接全输出1

第二种情况: 智商q<n , 对于大于智商的比赛需要考虑要不要参加, 从后往前贪心就是最优解, 最后的智商是0, 每当有大于智商的比赛就智商+1, 注意增加智商的次数不超过q, 超过q且智商小于比赛的时候就不能参加比赛了, 最后注意倒序输出, 否则顺序不对也会wa

ac代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, b) for (ll i = (a); i <= (b); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepr(i, a, b) for (ll i = (b); i > (a); i--)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)

ll cnt,n,m,t,ans,ant;
const int N=1e5+10;
ll arr[N];
string str;

inline ll read()
{
    char c = getchar();int x = 0,s = 1;
    while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}//是符号
    while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}//是数字
    return x*s;
}


void solve()
{
    ll q;
    str.clear();
    ans=0;
    scanf("%lld%lld",&n,&q);
    rep(i,1,n) 
        scanf("%lld",&arr[i]);
    if(q>=n) 
    {
        rep(i,1,n) cout<<'1';
        puts("");
		return;
    }
	cnt=0;//最后的智商
    rrep(i,1,n)
    {
        if(cnt>=arr[i])
        {
            str.push_back('1');
        }else if(cnt<arr[i]&&q) 
        {
            q--;
			cnt++;
            str.push_back('1');
        }else
		{
			str.push_back('0');
		}
    }
	reverse(str.begin(),str.end());
    cout<<str<<endl;
    return;
}

int main()
{
    cin>>t;
    while(t--)
        solve();
    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值