链接:
I. Invading system
1000ms
1000ms
65536KB
64-bit integer IO format:
%lld Java class name:
Main
Font Size:
Eyelids is a student in WHU, at the same time he is a hacker. Shortly after the end of the examination, he was surprised to find he had failed in advanced mathematics, so he decisively invaded School Academic Department website. In the process of invasion, he found that the contents related to the score is an encrypted file, this file consisted by n numbers, after analysis, he find the password of the encrypted file was the number whose binary form has the least 1 among these n numbers. However, as there are too many numbers, Eyelids hopes you can help him decipher the password, to change the score before the results will be finally announced.
Input
The first line is an integer T indicates the number of test cases.
Input contains multiple test cases.
For each test case, the first line has a number n (1<=n<=10^5), showing the number of the numbers. The second line contains n integers separated by blank, showing the n numbers in the file (1<=ai<=10^9).
Input contains multiple test cases.
For each test case, the first line has a number n (1<=n<=10^5), showing the number of the numbers. The second line contains n integers separated by blank, showing the n numbers in the file (1<=ai<=10^9).
Output
For each set of data, output the case number first, then the key in a line. If there are more than one number are eligible, output the smallest one.
Sample Input
1
5
3 2 4 5 6
5
3 2 4 5 6
Sample Output
Case 1: 2
总结:第一场组队赛来迟了。Orc先是一个人战,最后 lrbj 又出了一题,就我表现最不好了。赛后又在死磕前面未完成的计算几何,先贴个签到的代码吧。
后面的要快点做完。
code:
/**
题意:给你一系列的数字,把他们转换成二进制,求出二进制中的数字 1 的个数
输出 1 的个数最少的,且数值最小的数字。
*/
#include<stdio.h>
int cal(int n)
{
int ans = 0;
while(n > 0)
{
if(n&1) ans++; //如果是奇数 +1 偶数 0 不管
n >>= 1;
}
return ans;
}
int main()
{
int T;
int n;
scanf("%d", &T);
for(int t = 1; t <= T; t++)
{
scanf("%d", &n);
int a;
scanf("%d", &a);
int ans = a; //先找第一个数
int bin = cal(a);
for(int i = 1; i < n; i++)
{
scanf("%d", &a);
if(cal(a) < bin ||(cal(a) == bin && a < ans) )
{// 1 的个数更小, 或者 1 的个数一样,但是数值更小
bin = cal(a); ans = a;
}
}
printf("Case %d: %d\n", t,ans);
}
return 0;
}