2018CCPC吉林赛区(重现赛)- 1003 Justice

Problem Description

Put simply, the Justice card represents justice, fairness, truth and the law. You are being called to account for your actions and will be judged accordingly. If you have acted in a way that is in alignment with your Higher Self and for the greater good of others, you have nothing to worry about. However, if you have
acted in a way that is out of alignment, you will be called out and required to own up to your actions. If this has you shaking in your boots, know that the Justice card isn’t as black and white as you may think.


On the table there are n weights. On the body of the i-th weight carved a positive integer ki , indicating that its weight is 12ki gram. Is it possible to divide the n weights into two groups and make sure that the sum of the weights in each group is greater or equal to 12 gram? That’s on your call. And please tell us how if possible.

Input

In the first line of the input there is a positive integer T (1 ≤ T ≤ 2000), indicating there are T testcases.
In the first line of each of the T testcases, there is a positive integer n (1 ≤ n ≤ 105 , ∑n ≤ 7 × 105 ), indicating there are n weights on the table.
In the next line, there are n integers ki (1 ≤ ki ≤ 109 ), indicating the number carved on each weight.

Output

For each testcase, first print Case i : ANSWER in one line, i indicating the case number starting from 1 and ANSWER should be either YES or NO, indicating whether or not it is possible to divide the weights. Pay attention to the space between : and ANSWER.
If it’s possible, you should continue to output the dividing solution by print a 0/1 string of length n in the next line. The i -th character in the string indicating whether you choose to put the i-th weight in group 0 or group 1.

Sample Input

3 
3 
2 2 2 
3 
2 2 1 
2 
1 1

Sample Output

Case 1: NO 
Case 2: YES 001 
Case 3: YES 10

【题解】

一个1的效果等于两个2,一个2效果等于两个3(1/2==1/4+1/4,1/4==1/8+1/8),那么两堆就至少有一个1就能满足类推~ 只要满足了 剩下的随便丢在哪一堆就可以了

#include<bits/stdc++.h>
using namespace std;
int vis[100010];
struct node{
    int id;
    int x;
}a[100010];
int cmp(const node &xx,const node &yy)
{
    return xx.x<yy.x;
}
int main()
{
    int n,repeat;
    scanf("%d",&repeat);
          int Case=1;
    while(repeat--)
    {
        scanf("%d",&n);
         
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i].x);
            a[i].id=i;
            vis[i]=0;
        }
        printf("Case %d: ",Case++);
        sort(a+1,a+1+n,cmp);
        
        int flag=1;
        int pre=1;       
        int num1=1,num2=1;
        for(int i=1;i<=n;i++)
        {
            while(num1+num2<=n-i+1&&pre<a[i].x)
            {
                num1=num1*2;
                num2=num2*2;
                pre++;
            }
            if(num1+num2>n-i+1)
            {
                flag=0;
                break;
            }
            if(num1)
            {
                num1--;
                vis[a[i].id]=1;
            }
            else
            {
                num2--;
            }
            if(!num1 && !num2) break;
        }
        if(flag==0 || num1 || num2) printf("NO\n");
        else
        {
            printf("YES\n");
            for(int i=1;i<=n;i++)
            {
                printf("%d",vis[i]);
            }
            printf("\n");
        }
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值