题目
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/2ki 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 1/2 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

题意
给n个砝码,每个编号ki,每个砝码重量1/2ki,问能不能把所有砝码分成两组,每一组的重量和都不小于1/2,如果可以,给出分组方案

思路
用map记录现在的编号ki的数量,如果有两个ki就合成一个ki-1。

代码

#include<bits/stdc++.h>
using namespace std;#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)const int MAXN = 1e5 + 5;int t, n;
struct node {int k, num;
}a[MAXN];bool cmp(node a, node b) {return a.k < b.k;
}
int ans[MAXN];
unordered_map<int,int> mp;
int main(void) {IO;cin >> t;for(int c = 1; c <= t; c++) {cout << "Case " << c << ": ";memset(ans, 0, sizeof(ans));cin >> n;for(int i = 1; i <= n; i++) {cin >> a[i].k;a[i].num = i;}sort(a + 1, a + n + 1, &cmp);mp.clear();int now, pos = -1;for(int i = 1; i <= n; i++) {now = a[i].k;while(now >= 2 && mp[now]) mp[now] = 0, now--;mp[now] = 1;if(now == 1) {pos = i + 1;break;}}if(pos == -1) {cout << "NO" << '\n';continue;}mp.clear();for(int i = pos; i <= n; i++) {now = a[i].k;ans[a[i].num] = 1;while(now >= 2 && mp[now]) mp[now] = 0, now--;mp[now] = 1;if(now == 1) {pos = -1;break;}}if(pos == -1){cout << "YES" << '\n';for(int i = 1; i <= n; i++) {cout << ans[i];}cout << '\n';}else {cout << "NO" << '\n';}}
}

HDU - 6557 Justice相关推荐

  1. HDU题目分类大全【大集合】

    基础题: 1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.  1032.1037.1040.1048.1056.105 ...

  2. HDU 4389 - X mod f(x)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4389 2012多校,第9场,1010 . 问题是,询问区间内 存在多少个 哈沙德数(Harshad ...

  3. 转载:Hdu 题目分类

    原址点击 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056. ...

  4. hdu与poj题目分类

    POJ 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(po ...

  5. hdu 4389 囧,打表

    http://acm.hdu.edu.cn/showproblem.php?pid=4389 题意 :一个数能被他各个位数之和整除则符合要求,给L,R,问区间里有多少个数符合要求. 囧,居然打表就能过 ...

  6. hdu HDOJ 题目分类(转)

    动态规划:2037 2054 2084 hdu题目分类(转) http://apps.hi.baidu.com/share/detail/17053154 1001 整数求和 水题 1002 C语言实 ...

  7. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  8. hdu 5438 Ponds 拓扑排序

    Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...

  9. HDU 1248 寒冰王座(全然背包:入门题)

    HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...

最新文章

  1. Activiti源码之建造者模式 Builder
  2. GPU Gems2 - 13 动态环境光遮蔽与间接光照(Dynamic Ambient Occlusion and Indirect Lighting)
  3. 最近的一些校招试题摘录
  4. 作者:郭琨(1985-),女,博士,中国科学院虚拟经济与数据科学研究中心助理研究员...
  5. Python PEP8 编码规范中文版
  6. android联系人源码分析,android 联系人源码分析 新字段的添加流程
  7. MyBatis-Plus入门篇——CRUD
  8. Rust : Box 为什么这里并不需要拆箱?
  9. Shell脚本基础语法教程
  10. 【路由器】OpenWrt 手动编译 ipk
  11. php 系统管理和监控软件
  12. eclipse 背景绿豆沙颜色
  13. “二清”是电商行业在支付清算领域中普遍存在的现实状况?
  14. 树莓派开发板Android Things镜像烧录
  15. 如何解决 Android浏览器查看背景图片模糊的问题?
  16. Mackevision 发布 2016 年回顾与展望
  17. 个人家用nas_家庭私有云盘系列教程-本地搭建家庭NAS方案
  18. 机房布线的至高境界,美到窒息
  19. java圈子_从JAVA入了这个圈子,有多少老司机和他一样?
  20. pdf转换器绿色版使用方法

热门文章

  1. 了解C#中ref和out关键字的不同
  2. python求矩阵的谱半径
  3. 去百度还是去创新工厂?信开复还是信彦宏?
  4. c语言叶子,一片很好看的叶子
  5. 戏说PUBER之----LULU与绿猪的故事(2)
  6. Unity 报错之 java.net.MalformedURLException: unknown protocol
  7. 泰拉瑞亚mod鸿蒙方舟,三款高评分的沙盒生存类手游,经典之作泰拉瑞亚你有玩过吗?...
  8. 中软国际解放号创新IT众包 打造“杰客之家”
  9. 【论文复现】中值滤波改进:Noise Adaptive Fuzzy Switching Median Filter(NAFSMF)
  10. Baxter官方例程