TOJ 3455.Diamonds
2017-07-09 21:01
316 查看
题目链接:http://acm.tju.edu.cn/toj/showp3455.html
3455. Diamonds
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 327 Accepted Runs: 140 Multiple test files
John and Kate found 10 diamonds, each of which has an integer value. They want to divide these diamonds into two parts, one of which will belong to John and the other will belong to Kate. Of cause the two
friends both holp to get as more valuable as possible. For equity reason, they will devide these diamonds in such way: at first John divide these diamonds into to part freely, then Kate take one part, and the other part belongs to John. Now the question is
how much value can John get at most?
0 and 1000 (inclusively) represent the value of the ten diamonds.
10颗钻石总共有2^9种可能性,也不多,直接暴力遍历一遍就行了。
3455. Diamonds
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 327 Accepted Runs: 140 Multiple test files
John and Kate found 10 diamonds, each of which has an integer value. They want to divide these diamonds into two parts, one of which will belong to John and the other will belong to Kate. Of cause the two
friends both holp to get as more valuable as possible. For equity reason, they will devide these diamonds in such way: at first John divide these diamonds into to part freely, then Kate take one part, and the other part belongs to John. Now the question is
how much value can John get at most?
Input
The first line of input is an integer T (1 ≤ T ≤ 100) indicate the number of test cases. Then T lines follows, each line has 10 integers, all of which are integers and between0 and 1000 (inclusively) represent the value of the ten diamonds.
Output
For each test cases, output a single line: the most value John can get.Sample Input
1 1 1 1 2 1 1 1 1 1 1
Sample Output
5
10颗钻石总共有2^9种可能性,也不多,直接暴力遍历一遍就行了。
#include <stdio.h> #include <algorithm> using namespace std; int main(){ int n,s1,s2,tmp,a[10]; scanf("%d",&n); while(n--){ for(int i = 0;i < 10;i++) scanf("%d",&a[i]); int ans = 0; for(int j = 0;j < (1 << 9);j++){ s1 = s2 = 0; for(int i = 0;i < 10;i++) if(j & (1 << i)) s1 += a[i]; else s2 += a[i]; ans = max(ans, min(s1,s2)); } printf("%d\n",ans); } return 0; }
相关文章推荐
- TOJ_1002解题报告
- toj 2798 Farey Sequence
- toj 2696 Collecting Beepers
- TOJ 1398 Square --DFS
- TOJ 1684. Power Network 【第一道网络流 】
- toj 2991 Simple Task II 二次剩余
- 加密问题 TOJ-1547
- TOJ 3843 快速排序 折半查找
- TOJ 1112 POJ 2939 Flavius Josephus Reloaded/哈希链求地址法
- TOJ 1183 HDU 1515 ZOJ 1004 Anagrams by Stack /深搜+栈
- toj1726 World Cup Noise
- TOJ 2641 Gene
- toj 3019 Hidden Password (最小表示法)
- TOJ 2909 ZOJ 3175 Number of Containers / 数论
- TOJ 2399
- TOJ 2711 Stars
- TOJ 1050 Courses 二分匹配
- TOJ 2674 Java Vs C++ 字符串处理
- TOJ 2733 棋盘游戏
- TOJ:1746. How many sums