Fox and Card Game CodeForces
来源:互联网 发布:nodejs 多个js 编辑:程序博客网 时间:2024/05/22 05:14
题意:有几堆牌,每一张牌上都有一个数字,两个人抽牌,A只能从牌顶抽,B只能从牌底抽。A先手,问,每个人都采取最优策略的情况下,最后两个人的值分别是多少
思路:首先,对于A和B来说,所有的牌都是已知的。对于偶数的牌堆,对于A来说,不管前一半是大于后面一半或者是小于,都没有意义,反正一人一半。对于奇数的,想去取最大的那个。
反正我觉得这题说证明过程说不出来,只能说好像是这样,似乎也蛮合乎道理的,看了网上很多的解题报告,其实讲的也不清的。 只能说贪心有时候要xjb贪心(当然要相对合理),然后结合下样例试试。 目前只能想到这了。
#include <bits/stdc++.h>using namespace std;typedef long long ll;int n;vector <int> a;bool cmp(const int& a,const int&b){ return a>b;}int main(void){ cin >> n; int sum1=0,sum2=0; for(int i=1;i<=n;i++) { int num; scanf("%d",&num); if(num%2==0) { for(int i=1;i<=num/2;i++) { int temp; scanf("%d",&temp); sum1+=temp; } for(int i=1;i<=num/2;i++) { int temp; scanf("%d",&temp); sum2+=temp; } } else { int temp; for(int i=1;i<=num/2;i++) { scanf("%d",&temp); sum1+=temp; } scanf("%d",&temp); a.push_back(temp); for(int i=1;i<=num/2;i++) { int temp; scanf("%d",&temp); sum2+=temp; } } } //printf("%d %d\n",sum1,sum2); sort(a.begin(),a.end(),cmp); for(int i=0;i<a.size();i++) { if(i==0 || i%2==0) sum1+=a[i]; else sum2+=a[i]; } printf("%d %d\n",sum1,sum2);}
//这题刚拿到我就想到贪心了,接下来我想着贪心策略,想着想着就想错了(我以为是对的)。然后一直就想怎么去实现我的思路,结果放弃了,因为很难实现。 `
// DIV 1的C题。 意想不到的做了div1 ,其实发现题目没有想象中的那么难,感谢岐哥的套路
通过这题我学到了什么?
1.比赛的时候,碰到贪心的题,一定要敢去想,有时候xjb贪心,证明过程给不出来,但贪心策略合情合理的,很有可能是对的。
阅读全文
0 0
- Codeforces---Fox and Card Game
- Fox and Card Game CodeForces
- codeforces 388C Fox and Card Game
- Codeforces 388 C. Fox and Card Game
- CodeForces 388C Fox and Card Game
- Codeforces Round #228 Fox and Card Game 解题报告
- Codeforces 388C Fox and Card Game(贪心)
- Codeforces #228 D2E / D1C:Fox and Card Game
- Codeforces Round #228 (Div. 1) C. Fox and Card Game
- Codeforces 388C Fox and Card Game 博弈
- CodeForces 388C Fox and Card Game 解题报告
- Codeforces Round #228 (Div. 1)C. Fox and Card Game
- Codefrces 388C Fox and Card Game
- codeforces Fox and Number Game
- Codeforces Round #228 (Div. 2) E Fox and Card Game(贪心博弈)
- Appleman and Card Game CodeForces
- Codeforces 389A Fox and Number Game
- codeforces A. Fox and Number Game
- web基础知识回顾
- java代码混淆工具Jocky的介绍
- 【HDU-1234】 开门人与关门人
- How to Install TestLink on CentOS 7
- AtCoder GC 018A: Getting Difference 题解
- Fox and Card Game CodeForces
- linux SVN路径带用户名拉取
- 简单工厂设计模式(Simple Factory)
- python科学计算笔记(二)pandas获取网络文件
- 计算机基础——JAVA位操作
- 虚拟机克隆CentOS6.5之后网卡的配置
- sublime text 3 安装ctags
- Android——Android基础控件
- windows上IPC配置不当利用以及防护