Codefrces 388C Fox and Card Game

Source: Internet
Author: User
Tags sort

Title Link: Http://codeforces.com/problemset/problem/388/C


Test instructions: There are n decks on the table, each card has a weight, a person can take a card from the top of the pile, one can take a card from the bottom of the pile, taking turns until the card is not, all choose the best strategy, ask the last of their respective card weights and


Idea: Just started to think ... Each time to take the biggest card is not good, and then hit the face, according to game theory strategy because both sides have to suppress each other, each set of cards they each take half, if there is one last and all the rest of the sort to take turns


#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #define MAXN 1030 u

Sing namespace std;

int S[MAXN];
    int main () {int n,m;
        while (scanf ("%d", &n)!=eof) {int res1=0,res2=0,cnt=0;
           for (int j=0;j<n;j++) {//cout<< ":" <<j<<endl;
           scanf ("%d", &m);
                   if (m%2==0) {for (int i=1;i<=m;i++) {int tem;
                   scanf ("%d", &tem);
                   if (I&LT;=M/2) Res1+=tem;

               else Res2+=tem; }} else {for (int i=1;i<=m;i++) {i
                   NT TEM;
                   scanf ("%d", &tem);
                   if (I&LT;=M/2) Res1+=tem;
                   else if (i==m/2+1) S[cnt++]=tem;

               else Res2+=tem;
   }}} sort (s,s+cnt);     int flag=1;
            for (int i=cnt-1;i>=0;i--) {if (flag==1) res1+=s[i];
            else Res2+=s[i];
        Flag=!flag;
    } printf ("%d%d\n", res1,res2);
 }
}


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.