Codeforces Round #228 (Div. 1) C greedy

Source: Internet
Author: User

Codeforces Round #228 (Div. 1) C greedy

Ga ga, I was delayed by some things today, but I still have A few questions. This question is not bad.

Question link:


Two people play games, with N piles of cards and numbers on them. A can only take one of the top cards in N stacks at A time, B can only take one of the cards at the bottom of N heap. A and B want to maximize their sum and ask the last score.


After drawing, if the number of cards in a pile is an even number, it is found that two people are divided by half each, because if the other party wants to take the big card that belongs to his half from here, he will have time to block it,

Next there is an odd number. In fact, the odd number is the first card in the middle, and the other two is half of each card. Therefore, we should greedy each odd number of cards in the middle,


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
 
   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<
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.