Gaga, I was delayed by something today, but I still got A on a few questions. This question was pretty good
Question link:
Question: Two people play a game. There are N piles of cards with numbers on them. A can only take the top card of one of the N piles at a time, and B can only take the bottom card of one of the N piles. A , B wants to get the maximum sum, and asks what the final score is
Draw it, and if the number of cards in a certain pile is an even number, you find that it is actually two Each person divides it half, because if the other party wants to take away the larger cards that belong to his own half, he can stop it in time.
The next step is the odd number, and the one who goes first will actually grab the odd number. For the middle card, the other two halves are still half each, so greed should be based on the size of the middle card of each odd-numbered pile,
int n;typedef struct Node { int mid; int id;};Node node[100 + 55];int mp[100 + 55][100 + 55];int ss[100 + 55];void init() { memset(ss,0,sizeof(ss)); memset(node,0,sizeof(node));}bool input() { while(cin>>n) { return false; } return true;}bool cmp(Node x,Node y) { return x.mid > y.mid;}void cal() { int ans1 = 0; int ans2 = 0; int cnt = 0; for(int i=0;i<n;i++) { scanf("%d",&ss[i]); if(ss[i]&1) { for(int j=1;j<=ss[i];j++) { scanf("%d",&mp[i][j]); if(j == (ss[i] + 1)/2) { node[cnt].id = i; node[cnt++].mid = mp[i][j]; } } } else { for(int j=1;j<=ss[i];j++) { int x; scanf("%d",&x); if(j <= ss[i]/2) ans1 += x; else ans2 += x; } } } sort(node,node + cnt,cmp); int mark = 1; for(int i=0;i<cnt;i++) { if(mark > 0) { int k = node[i].id; for(int j=1;j<=(ss[k] + 1)/2;j++) ans1 += mp[k][j]; for(int j=(ss[k] + 1)/2 + 1;j<=ss[k];j++) ans2 += mp[k][j]; } else { int k = node[i].id; for(int j=1;j<=ss[k]/2;j++) ans1 += mp[k][j]; for(int j=(ss[k] + 1)/2;j<=ss[k];j++) ans2 += mp[k][j]; } mark *= -1; } cout<<ans1<<" "<<ans2<<endl;}void output() {}int main() { while(true) { init(); if(input())return 0; cal(); output(); } return 0;}