Google Code Jam 2014 Qualification Round:D. Deceitful War
来源:互联网 发布:智能小车pid算法 编辑:程序博客网 时间:2024/05/17 07:57
把半年前的blog重写一下,顺便熟悉一下这种考智商的博弈题。
题意:
N和K各有一堆石头,N知道两个人所有石头的重量,K只知道自己石头的重量,N选一个石头,把它的重量告诉K,如果是deceitful war, 这个told value就不一定是真实值,但是要保证,chose N>chose K if and only if told N>Told K(否则称天平时会露馅)并且told value!=K的任意一个石头的重量,如果是war,N的told value就是真实值把两个石头放在天平上称重,重的得一分。
对于War而言,因为N是先手,所以对于N取的每一个stone,K都会取一个最小的比它重的石头(if K has),如果K没有这样的石头存在,K lose 1 credit
对于Deceitful War,因为N可以谎报重量,所以N要用自己最轻的石头抵掉K最重的石头,所以从小到大遍历,如果N发现自己的某个石头比K的当前石子集合中最轻的石头重,那么N可以报一个很大的值,K所有stone都达不到这个值,所以K会选一个最轻的石头输给R以减小损失(K有更多重的石头最后的胜算才更大)。所以最后N剩下的都是轻的石头,和K的重的石头抵掉了。
#include<iostream>#include<stdio.h>#include<stdlib.h>#include<vector>#include<string>#include<cstring>#include <cmath>#include<algorithm>#include<stack>using namespace std;int T;int N;double na[1010];double ke[1010];int sn;int sk;int sn2;int sk2;void solve(){ sn=0; sk=0; sn2=0; sk2=0; sort(na,na+N); sort(ke,ke+N);// for(int i=0;i<N;i++)// cout<<na[i]<<endl; //War int st=0; for(int i=0;i<N;i++) { for(int j=st;j<N;j++) { if(ke[j]>na[i]) { sk++; st=j+1; break; } } } // cout<<sk<<"++"<<endl; sn=N-sk; st=0; //D-War for(int i=0;i<N;i++)//Ke { for(int j=st;j<N;j++)//Na { if(na[j]>ke[i]) { sn2++; st=j+1; break; } } }}int main(){ freopen("D-large.in","r",stdin); // freopen("input.txt","r",stdin); freopen("d-large.out","w",stdout); scanf("%d",&T); for(int i=1;i<=T;i++) { scanf("%d",&N); for(int i=0;i<N;i++) scanf("%lf",&na[i]); for(int i=0;i<N;i++) scanf("%lf",&ke[i]); solve(); printf("Case #%d: %d %d\n",i,sn2,sn); } return 0;}
0 0
- Google Code Jam 2014 Qualification Round:D. Deceitful War
- Google Code Jam Qualification Round 2014 Problem D. Deceitful War 题解
- Google Code Jam 2014 Problem D. Deceitful War
- Google Code Jam 2014 Qualification Round 2014 A B D
- Google Code Jam 2014-Qualification Round-Problem C. Minesweeper Master
- Google Code Jam 2014 Qualification Round:Problem A. Magic Trick
- 2009 Google Code Jam Qualification Round 题解
- Google Code Jam 2011 Qualification Round ProblemA
- Google Code Jam 2012 Qualification Round
- Google Code Jam Qualification Round 2012
- Google Code Jam 2012 Qualification Round. Problem D. Hall of Mirrors
- Google Code Jam 2015 Qualification Round: Problem D. Ominous Omino 【Small Input】
- Reverse-GOOGLE CODE JAM AFICA 2010 Qualification Round
- T9 Spelling-GOOGLE CODE JAM AFICA 2010 Qualification Round
- Store Credit-GOOGLE CODE JAM AFICA 2010 Qualification Round
- ACM-GOOGLE CODE JAM 2011 Qualification Round 2011(总结)
- Google Code Jam 2010 Qualification Round 2012 Problem B && C
- Google Code jam Qualification Round 2015 解题报告
- csdn好平台好网站
- Embarcadero RAD Studio XE6 安装没有 FireMonkey Mobile Application 解决方法
- input_dev结构体分析
- matlab 下 txt文件读取
- Codeforces round #247 for Div. 2
- Google Code Jam 2014 Qualification Round:D. Deceitful War
- 对于在textarea中用enter来提交表单之后又要清空其textarea中的值的时候
- Scala 脚本
- 认清自己的主干,不能大钱小钱都同等抓
- window下跑nginx,轻松实现负载均衡
- 树状数组&线段树&RMQ
- 关于Outlook Express里的.dbx的文件
- lr的并行化
- MD5加密