http://codeforces.com/contest/389/problem/E
题意:给你n个序列,然后两个人x,y,两个人玩游戏,x从序列的前面取,y从序列的后面取,两个人都想自己得到的数的和尽可能大,最后输出两个人得到的数的和。
思路:如果序列的个数为偶数的话,前面一半为x所得,后面一半为y所得; 如果为奇数的话,中间的数根据它的大小决定谁得到。这样的处理方式因为两个人都尽可能的取得序列中的最大,在谁的那一半数大的,另一个人取不到,有的时候可以先放一放,去取别人即将取到的数。
1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <vector> 5 #include <algorithm> 6 #define ll long long 7 #define maxn 1000 8 using namespace std; 9 10 int n; 11 int x[maxn]; 12 13 int main() 14 { 15 scanf("%d",&n); 16 int ans1=0,ans2=0; 17 int x,k; 18 vector<int>q; 19 while(n--) 20 { 21 scanf("%d",&k); 22 for(int i=1; i<=k/2; i++) 23 { 24 scanf("%d",&x); 25 ans1+=x; 26 } 27 if(k%2) 28 { 29 scanf("%d",&x); 30 q.push_back(x); 31 } 32 for(int i=1; i<=k/2; i++) 33 { 34 scanf("%d",&x); 35 ans2+=x; 36 } 37 } 38 sort(q.begin(),q.end()); 39 int cnt=0; 40 for(int i=(int)q.size()-1; i>=0; i--) 41 { 42 if(cnt%2==0) ans1+=q[i]; 43 else ans2+=q[i]; 44 cnt++; 45 } 46 printf("%d %d\n",ans1,ans2); 47 return 0; 48 }