UVa12614 - Earn For Future
来源:互联网 发布:任我行 陈奕迅 知乎 编辑:程序博客网 时间:2024/06/06 08:50
In a lazy afternoon the great Froogrammer came to realize that, to make his future plans successful he needs a lot of money. To make some quick cash he decided to go to the casino to play a game. The rule of the game is the following:
- The player is given N cards. Each card has a non-negative integer printed in it.
- The player will choose some cards from the given cards.
- The bitwise AND value of the chosen cards will be calculated and the player will be given the same amount of money. (i.e. equal to the bitwise AND value of the chosen cards).
After getting N cards Froogrammer was in a fix as usual. He could not decide which of the cards to choose. So he called you to help him. Please tell him the maximum amount he can win from these set of cards. If you are confused about bitwise AND operation see the notes section below.
Input
The first line of input will contain the number of test cases T (T < 101). Then there will be T test cases. Each of the test cases will start with an integer N ( 0 < N < 31) denoting the number of cards. Then the following line will contain N non-negative integers Ci ( 0Ci < 231) separated by space, denoting the numbers printed on each of the cards.
Output
For each test case print one line of output denoting the case number and the maximum amount Froogrammer can win. See sample output for exact format.
Note:
A bitwise AND takes two binary representations of equal length and performs the logical AND operation on each pair of corresponding bits. The resulting bit of a position is 1 if the bit at that position of both numbers is 1; otherwise, that bit is 0.
For example:
0101 (decimal 5) AND 0011 (decimal 3) = 0001 (decimal 1)
Sample Input
120 1
Sample Output
Case 1: 1
#include <cstdio>#include <algorithm>using namespace std;const int N = 31;int num[N];int n;void input(){scanf("%d", &n);for (int i = 0; i < n; i++) {scanf("%d", &num[i]);}}void solve(int cas){int ans = *max_element(num, num + n);printf("Case %d: %d\n", cas, ans);}int main(){#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);#endifint t;scanf("%d", &t);for (int i = 1; i <= t; i++) {input();solve(i);}return 0;}
- UVa12614 - Earn For Future
- For future For you
- Bles for the future
- fighting for the future
- Some Ways to earn extra money for Embeded Developer
- Create a future for yourself
- Cyclopaedia for My Future Children
- The Plan for Future two years
- One day gotta change for my future
- What is the future for ABAPers?
- The future for mobile application development
- What is the Future for SharePoint?
- what to do for the future?
- Some Resources For the new comming future
- Future
- future
- future
- Future
- RPC框架几行代码就够了
- 各种网站和插件
- Oracle存储过程详解
- PS入门
- 10个顶级的CSS UI开源框架
- UVa12614 - Earn For Future
- c++ 析构函数的调用
- 八大排序经典算法(图解+参考源代码)
- 【学习】数据挖掘准则
- 一个自己编写JS日历
- 状态压缩 之 hdu 1074 Doing Homework
- c++定时模块
- Android抓包之Tcpdump和WireShark__7
- 程序员收入排行:Java最高