codeforces 388C Fox and Card Game

刚刚看到这个题感觉是博弈题;

不过有感觉不像,应该是个贪心;

于是就想贪心策略;

举了一个例子:

3

3 1 2 3

4 3 4 1 2

5 4 1 2 5 8

如果他们两个每次都拿对自己最有利的那个的话,C的得分是14分;

但是C作为第一个选手,他有更好的策略,只拿前一半,后一半给J,中间的再分;这样的话C的得分就能达到15分;

同样J也有这样的策略,他也能保证自己最少能拿到后一半的分(跟风式的拿);

这样的话,贪心策略就明朗了!

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 105
using namespace std;

int s[maxn];
int c,j;
int main()
{
    int n,num;
    int t,cnt=0;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&t);
        for(int k=0; k<t/2; k++)
        {
            scanf("%d",&num);
            c+=num;
        }
        if(t&1)
        {
            scanf("%d",&s[cnt]);
            cnt++;
        }
        for(int k=0; k<t/2; k++)
        {
            scanf("%d",&num);
            j+=num;
        }
    }
    sort(s,s+cnt);
    bool flag=1;
    for(int i=cnt-1; i>=0; i--)
    {
        if(flag)
            c+=s[i];
        else
            j+=s[i];
        flag=!flag;
    }
    printf("%d %d",c,j);
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/yours1103/p/3560729.html