TJU ACM Problem 【4158】
来源:互联网 发布:虚拟局域网 软件 推荐 编辑:程序博客网 时间:2024/05/16 13:04
Alice and Bob like game. They often play the game together.
Today, they are playing a card game. At first, there are
First, Alice choose one card from the first card and the last card.
And then Bob choose one card from the first card and the last card of the remaning
And then Alice choose one card from the first card and the last card of the remaning
...end until there is no card.
they can get points from the number on the cards. The winner whose point is most.
For example, there are 3 cards, 3 7 5. First, Alice can choose 3 and 5. Alice choose 5, and then Bob can choose 3 and 7, Bob choose 7, and then Alice choose 3. The point of Alice is 8, and point of Bob is 7. So Alice is winner, and the difference of points is 1.
Now, give you
Input
The input consists of multiple test cases. The first line contains an integer
Each case contains two lines, the first line contains one integer
The second contains
Output
For each case output the difference of points of Alice and Bob
Sample Input
333 10 543 7 8 541 1 1 1
Sample Output
-210#include <iostream>#include <string>#include<cstdlib>using namespace std;int main(){ int t,n,i; int a[20]; cin>>t;//用例组数 int beg,fin; int alice,bob; while(t--) { alice=0; bob=0; cin>>n; beg=0; fin=n-1; for(i=0;i<n;i++) cin>>a[i]; for(i=1;i<=n;i++) { if(beg<=fin) { if(i%2!=0)//alice选择 { if(a[beg]>=a[fin]) { alice+=a[beg]; beg++; } else if(a[beg]<=a[fin]) { alice+=a[fin]; fin--; } } else//bob选 { if(a[beg]>=a[fin]) { bob+=a[beg]; beg++; } else if(a[beg]<=a[fin]) { bob+=a[fin]; fin--; } } } } cout<<alice-bob<<endl; } return 0;}
- TJU ACM Problem 【4158】
- TJU ACM Problem【4157】
- TJU Root of the Problem
- tju 4069 kai's problem (hash)
- TJU-4107. A simple problem(贪心)
- TJU ACM-ICPC Online Judge—1191 The Worm Turns
- Euclid Problem-ACM
- ACM Problem A
- ACM Problem B
- ACM Problem C
- [ACM]a+b problem
- [ACM]Sum Problem
- acm-A*B Problem
- acm-A-B Problem
- acm-A/B Problem
- acm-Train Problem I
- ACM-Train Problem I
- ACM Problem E
- 使用PowerDesigner创建JAVA类图
- sdutacm-数据结构实验之图论七:驴友计划
- c语言
- Toast自定义自己的布局
- tensorflow安装
- TJU ACM Problem 【4158】
- Hibernate中fetch和lazy介绍
- 吉萨服装APP项目
- Mongodb的安装及简单使用
- 无参方法调用的简单实例
- Java类型转换
- Hibernate迫切左外连接和迫切内连接
- C语言实现大数阶乘
- sdutacm-人活着系列之芳姐和芳姐的猪