ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CCPC 2018 吉林 C "JUSTICE" (数学)

2019-05-06 19:02:14  阅读:490  来源: 互联网

标签:JUSTICE ki there CCPC 1e5 2018 line your indicating


传送门

 

参考资料:

  [1]:https://blog.csdn.net/mmk27_word/article/details/89789770

 

题目描述
    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  1/(2^ki) gram. 
    Is it possible to divide then weights into two groups and make sure that the sum of the weights in each group is greater or equal to 1/2 gram? 
    That's on your call. And please tell us how if possible.

输入
    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≤1e5 , Σ n ≤ 7×1e5 ),indicating there areηweights on the table.
    In the next line, there are n integers ki (1≤ki≤1e9), indicating the number carved on each weight.


输出
    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.
题目描述
样例输入
3
3
2 2 2
3
2 2 1
2
1 1

样例输出
Case 1: NO
Case 2: YES
001
Case 3: YES
10
样例输入输出

 

题解看上述参考资料,下面谈谈我的进一步理解,以及,比赛时思路出现的错误:

  组成一个 1 / 2 需要

    21个 2, 22个23 , ....... , 2x-1个2x;

  那么,从幂最小的k向上递推,判断是否存在 x,y 使得 x 出现的次数 ≥ 2x-1 , y 出现的次数 ≥ 2y-1 次;

AC代码:

 

比赛时,看到 n 最大为 1e5 ,而1 / 2k 组成 1 / 2 至少需要 2k-1 个 k ,然后,找到了2k ≤ 1e5 的最大的 k = 17;

然后,就特判,当 ki > 20 时,就不管;

对于 ki ≤ 20 的情况,定义一个数组a,a[i] : k = i 的 k 的总个数;

每次都更新一遍数组 a;

1 for(int i=20;i >= 2;--i)
2 {
3   a[i-1] += a[i]/2;//两个i构成一个i-1
4   a[i] %= 2;
5 }

最后判断一下a[1]的个数,如果 < 2,输出"NO";

反之,输出"YES",并输出分组;

 

然后,今天下午debug了一下午,学弟给了我一组数据,顿悟了,debug成功;

当 k > 17 时,也可以组成 1 / 2;

x最大可取1e5,所以说,k最大也可到达1e5;

 

标签:JUSTICE,ki,there,CCPC,1e5,2018,line,your,indicating
来源: https://www.cnblogs.com/violet-acmer/p/10821397.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有