2014 ACM-ICPC Beijing Invitational Programming Contest
来源:互联网 发布:怎样做数据饼状图 编辑:程序博客网 时间:2024/06/06 04:46
点击打开链接
Happy Reversal
1000ms65536KB64-bit integer IO format: %lld Java class name: Main Font Size: Elfness is studying in an operation "NOT".For a binary number A, if we do operation "NOT A", after that, all digits of A will be reversed. (e.g. A=1001101, after operation "NOT A", A will be 0110010).Now Elfness has N binary numbers of length K, now he can do operations "NOT" for some of his numbers. Let's assume after his operations, the maximum number is M, the minimum number is P. He wants to know what's the maximum M - P he can get. Can you help him? Input
The first line of input is an integer T (T ≤ 60), indicating the number of cases.For each case, the first line contains 2 integers N (1 ≤ N ≤ 10000) and K (1 ≤ K ≤ 60), the next N lines contains N binary numbers, one number per line, indicating the numbers that Elfness has. The length of each binary number is K. Output
For each case, first output the case number as "Case #x: ", and x is the case number. Then you should output an integer, indicating the maximum result that Elfness can get.
Sample Input
25 61001000011000100010100011111115 700011010001011001001101110001001011
Sample Output
Case #1: 51Case #2: 103
Source
2014 ACM-ICPC Beijing Invitational Programming Contest给你n组由k个0或者1组成的二进制数。每个数可以翻转,求两个数的最大差值。
//152 ms 1788 KB#include<stdio.h>#include<algorithm>using namespace std;char s[107];long long ans[20007];int n,m;long long getnum(){ long long res=0,j=1; for(int i=m-1;i>=0;i--,j*=2) if(s[i]=='1')res+=j; return res;}int main(){ int t,cas=1; scanf("%d",&t); while(t--) { int k=0; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { scanf("%s",s); ans[k++]=getnum(); for(int j=0;j<m;j++) if(s[j]=='1')s[j]='0'; else s[j]='1'; ans[k++]=getnum(); } sort(ans,ans+k); long long ans1=ans[k-1]-ans[1]; long long ans2=ans[k-2]-ans[0]; long long p=ans[0],q=ans[k-1]; long long e=1<<(m-1); if((p^q)&e==e) printf("Case #%d: %lld\n",cas++,max(ans1,ans2)); else printf("Case #%d: %lld\n",q-p); } return 0;}
1000ms
65536KB
Elfness is studying in an operation "NOT".
For a binary number A, if we do operation "NOT A", after that, all digits of A will be reversed. (e.g. A=1001101, after operation "NOT A", A will be 0110010).
Now Elfness has N binary numbers of length K, now he can do operations "NOT" for some of his numbers.
Let's assume after his operations, the maximum number is M, the minimum number is P. He wants to know what's the maximum M - P he can get. Can you help him?
The first line of input is an integer T (T ≤ 60), indicating the number of cases.
For each case, the first line contains 2 integers N (1 ≤ N ≤ 10000) and K (1 ≤ K ≤ 60), the next N lines contains N binary numbers, one number per line, indicating the numbers that Elfness has. The length of each binary number is K.
For each case, first output the case number as "Case #x: ", and x is the case number. Then you should output an integer, indicating the maximum result that Elfness can get.
25 61001000011000100010100011111115 700011010001011001001101110001001011
Case #1: 51Case #2: 103
//152 ms 1788 KB#include<stdio.h>#include<algorithm>using namespace std;char s[107];long long ans[20007];int n,m;long long getnum(){ long long res=0,j=1; for(int i=m-1;i>=0;i--,j*=2) if(s[i]=='1')res+=j; return res;}int main(){ int t,cas=1; scanf("%d",&t); while(t--) { int k=0; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { scanf("%s",s); ans[k++]=getnum(); for(int j=0;j<m;j++) if(s[j]=='1')s[j]='0'; else s[j]='1'; ans[k++]=getnum(); } sort(ans,ans+k); long long ans1=ans[k-1]-ans[1]; long long ans2=ans[k-2]-ans[0]; long long p=ans[0],q=ans[k-1]; long long e=1<<(m-1); if((p^q)&e==e) printf("Case #%d: %lld\n",cas++,max(ans1,ans2)); else printf("Case #%d: %lld\n",q-p); } return 0;}
0 0
- 2014 ACM-ICPC Beijing Invitational Programming Contest
- 2014 ACM-ICPC Beijing Invitational Programming Contest E
- BNU 34990 Justice String 2014 ACM-ICPC Beijing Invitational Programming Contest
- ACM ICPC 2017 Warmup Contest 6(ACM Google Cup 2011 Invitational Programming Contest)
- 2014 Beijing Invitational
- 2013-2014 ACM-ICPC Brazil Subregional Programming Contest
- UVALive 7061 Dire Wolf (dp)(The 2014 ACM-ICPC Asia Beijing Regional Contest D)
- The 2014 ACM-ICPC BeiJing D
- [hihocoder1392]ACM/ICPC Beijing
- The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - G Panda
- The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - B Eliminate Witches!
- The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - G Panda
- The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - B_Eliminate Witches!
- 【树状数组】The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - G Panda
- 【栈+模拟】The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - B Eliminate Witches!
- Hdu 4089 Activation (概率dp) - 2011 ACM-ICPC Beijing Regional Contest Problem I
- The 2015 ACM-ICPC Asia Beijing Regional Contest K A Math Problem
- 4046 Panda(The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest)
- mac os x文件夹权限管理方法详解,配合终端terminal语法详述
- vb.net机房收费系统——存储过程
- 疯狂打地鼠游戏核心代码(鼠标变锤子)
- BeanUtils对数据的封装
- Android使用layer-list和selector
- 2014 ACM-ICPC Beijing Invitational Programming Contest
- DBCP数据库连接池配置的一种高效方法
- yum源配置
- linux 静态库和动态库的使用
- Html中的表单
- WebView
- 移动终端处理器构成和基带芯片概述
- 初探C++内存泄漏学习笔记
- http://rrurl.cn/bzszpN