TOJ3455 Diamonds
来源:互联网 发布:wepy 知乎 编辑:程序博客网 时间:2024/06/01 07:16
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 between 0 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
11 1 1 2 1 1 1 1 1 1
Sample Output
5
10颗钻石总共有2^9种可能性,直接遍历,这里新学到一个位运算实现遍历
#include <cstdio>#include <iostream>#include <cmath>using namespace std;int main(){ int T; scanf("%d",&T); while(T--){ int a[11]; for(int i = 0;i < 10;i++){ scanf("%d",&a[i]); } int ans = 0; for(int i = 0;i < (1 << 9);i++){//这里是精髓,用二进制第i位是0还是1表示a[i]取或者不取 int sum1 = 0,sum2 = 0; for (int j = 0;j < 10;j++){ if (i & (1 << j)) sum1 += a[j];//如果取a[j],sum1+=a[i] else sum2 += a[j]; } ans = max(ans,min(sum1,sum2)); } printf("%d\n",ans); } return 0;}
- TOJ3455 Diamonds
- Rihanna - Diamonds
- TOJ 3455.Diamonds
- Diamonds Are Forever. Services Are Not.
- CodeChef DEC17 C Total Diamonds 递推
- HEARTS, CLUBS, DIAMONDS, SPADES: PLAYERS WHO SUIT MUDS
- Lady-Datejust Pearlmaster Diamonds and white gold watches
- toms shoe outlet but it was so tall quality diamonds
- 【R语言 数据探索】实战 Diamonds数据集探索
- 计算机语言种类
- [Beijing wc2012]最多的方案
- 打开Java VisualVM
- Unity 安卓 AvProVideo 运行设置视频路径
- MySQL数据库使用——MySQL用户管理
- TOJ3455 Diamonds
- 基于java的电话本管理系统
- 解决Unity Vertex Shader 渲染丢失的问题
- deepmind_lab 运行以 _pk3结尾的文件的依赖的东西
- CentOS部署java项目环境
- SQL优化
- Deep Forest:一种深度神经网络的替代模型架构
- Arrays.binarySearch()返回值问题
- python中的“self”