Google Code Jam 2014 资格赛:Problem D. Deceitful War
This problem is the hardest problem to understand in this round. If you are new to Code Jam, you should probably try to solve the other problems first.
Problem
Naomi and Ken sometimes play games together. Before they play, each of them gets Nidentical-looking blocks of wood with masses between 0.0kg and 1.0kg (exclusive). All of the blocks have different weights. There are lots of games they could play with those blocks, but they usually play something they call War. Here is how War works:
- Each player weighs each of his or her own blocks, so each player knows the weights of all of his or her own blocks, but not the weights of the other player's blocks.
- They repeat the following process N times:
- Naomi chooses one of her own blocks, with mass
ChosenNaomi. - Naomi tells Ken the mass of the block she chose.
- Ken chooses one of his own blocks, with mass
ChosenKen. - They each put their block on one side of a balance scale, and the person whose block is heavier gets one point.
- Both blocks are destroyed in a fire.
- Naomi chooses one of her own blocks, with mass
Naomi has realized three things about War. First, she has realized that she loses a lot. Second, she has realized that there is a unique strategy that Ken can follow to maximize his points without assuming anything about Naomi's strategy, and that Ken always uses it. Third, she has realized that she hates to lose. Naomi has decided that instead of playing War, she will play a game she calls Deceitful War. The great thing about Deceitful War is that Ken will think they're playing War!
Here is how Deceitful War works, with differences between Deceitful War and War in bold:
- Each player weighs each of his or her own blocks. Naomi also weighs Ken's blocks while he isn't looking, so Naomi knows the weights of all blocks and Ken only knows the weights of his own blocks.
- They repeat the following process N times:
- Naomi chooses one of her own blocks, with mass
ChosenNaomi. - Naomi tells Ken a number,
ToldNaomi, between 0.0kg and 1.0kg exclusive. Ken, who thinks they're playing War, thinks the number Naomi just told him isChosenNaomi. - Ken chooses one of his own blocks, with mass
ChosenKen. - They each put their block on one side of a balance scale, and the person whose block is heavier gets one point.
- Both blocks are destroyed in a fire.
- Naomi chooses one of her own blocks, with mass
Naomi doesn't want Ken to know that she isn't playing War; so when she is choosing which block to play, and what mass to tell Ken, she must make sure that the balance scale won't reveal that ChosenNaomi ≠ ToldNaomi. In other words, she must make decisions so that:
ChosenNaomi > ChosenKenif, and only if,ToldNaomi > ChosenKen, andToldNaomiis not equal to the mass of any of Ken's blocks, because he knows that isn't possible.
It might seem like Naomi won't win any extra points by being deceitful, because Ken might discover that she wasn't playing War; but Naomi knows Ken thinks both players are playing War, and she knows what he knows, and she knows Ken will always follow his unique optimal strategy for War, so she can always predict what he will play.
You'll be given the masses of the blocks Naomi and Ken started with. Naomi will play Deceitful War optimally to gain the maximum number of points. Ken will play War optimally to gain the maximum number of points assuming that both players are playing War. What will Naomi's score be? What would it have been if she had played War optimally instead?
Examples
If each player has a single block left, where Naomi has 0.5kg and Ken has 0.6kg, then Ken is guaranteed to score the point. Naomi can't say her number is ≥ 0.6kg, or Ken will know she isn't playing War when the balance scale shows his block was heavier.
If each player has two blocks left, where Naomi has [0.7kg, 0.2kg] and Ken has [0.8kg, 0.3kg], then Naomi could choose her 0.2kg block, and deceive Ken by telling him that she chose a block that was 0.6kg. Ken assumes Naomi is telling the truth (as in how the War game works) and will play his 0.8kg block to score a point. Ken was just deceived, but he will never realize it because the balance scale shows that his 0.8kg block is, like he expected, heavier than the block Naomi played. Now Naomi can play her 0.7kg block, tell Ken it is 0.7kg, and score a point. If Naomi had played War instead of Deceitful War, then Ken would have scored two points and Naomi would have scored zero.
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a line containing a single integer N, the number of blocks each player has. Next follows a line containing N space-separated real numbers: the masses of Naomi's blocks, in kg. Finally there will be a line containing N space-separated real numbers: the masses of Ken's blocks, in kg.
Each of the masses given to Ken and Naomi will be represented as a 0, followed by a decimal point, followed by 1-5 digits. Even though all the numbers in the input have 1-5 digits after the decimal point, Ken and Naomi don't know that; so Naomi can still tell Ken that she played a block with mass 0.5000001kg, and Ken has no reason not to believe her.
Output
For each test case, output one line containing "Case #x: y z", where x is the test case number (starting from 1), y is the number of points Naomi will score if she plays Deceitful War optimally, and z is the number of points Naomi will score if she plays War optimally.
Limits
1 ≤ T ≤ 50.
All the masses given to Ken and Naomi are distinct, and between 0.0 and 1.0 exclusive.
Small dataset
1 ≤ N ≤ 10.
Large dataset
1 ≤ N ≤ 1000.
Sample
Input
4
1
0.5
0.6
2
0.7 0.2
0.8 0.3
3
0.5 0.1 0.9
0.6 0.4 0.3
9
0.186 0.389 0.907 0.832 0.959 0.557 0.300 0.992 0.899
0.916 0.728 0.271 0.520 0.700 0.521 0.215 0.341 0.458
Output
Case #1: 0 0
Case #2: 1 0
Case #3: 2 1
Case #4: 8 4
Google Code Jam 2014 资格赛:Problem D. Deceitful War的更多相关文章
- Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha
Introduction Cookie Clicker is a Javascript game by Orteil, where players click on a picture of a gi ...
- Google Code Jam 2014 资格赛:Problem C. Minesweeper Master
Problem Minesweeper is a computer game that became popular in the 1980s, and is still included in so ...
- Google Code Jam 2014 Round 1 A:Problem C. Proper Shuffle
Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...
- Google Code Jam 2014 Qualification 题解
拿下 ABD, 顺利晋级, 预赛的时候C没有仔细想,推荐C题,一个非常不错的构造题目! A Magic Trick 简单的题目来取得集合的交并 1: #include <iostream> ...
- Google Code Jam 2014 Round 1 A:Problem A Charging Chaos
Problem Shota the farmer has a problem. He has just moved into his newly built farmhouse, but it tur ...
- Google Code Jam 2014 Round 1 A:Problem B. Full Binary Tree
Problem A tree is a connected graph with no cycles. A rooted tree is a tree in which one special ver ...
- Google Code Jam 2014 Round 1B Problem B
二进制数位DP,涉及到数字的按位与操作. 查看官方解题报告 #include <cstdio> #include <cstdlib> #include <cstring& ...
- Google Code Jam 2014 总结
第一次参加ACM竞赛,对自己取得的成绩还满意. Round1A: Rank: 2446 Score: 9 (没有进前1000名,只能拼下次了) Round1B: Rank: 944 Score: 42 ...
- [C++]Saving the Universe——Google Code Jam Qualification Round 2008
Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...
随机推荐
- apache mod_speling.so 忽略URL大小写(自动纠错)
apache mod_speling.so 忽略URL大小写(自动纠错) 打开配置文件 httpd.conf 加入 LoadModule speling_module modules/mod_spe ...
- ScrollView起始位置不是最顶部的解决办法
最近遇到了打开带有ScrollView的页面布局默认起始位置不是最顶部的情况,最后发现问题是因为ScrollView内部嵌套了gridview,只需要设置gridview获取焦点为false即可. g ...
- flask控制上传文件的大小
1.flask控制上传文件的大小的方案是全局控制:http://docs.jinkan.org/docs/flask/patterns/fileuploads.html from flask impo ...
- 一篇不错的讲解Java异常的文章(转载)----感觉很不错,读了以后很有启发
六种异常处理的陋习 你觉得自己是一个Java专家吗?是否肯定自己已经全面掌握了Java的异常处理机制?在下面这段代码中,你能够迅速找出异常处理的六个问题吗? OutputStreamWriter ou ...
- python下性能提示
性能提示 3.1 嵌套if/else结构比一系列单选if结构块,因为只要有一个条件满足,其余测试就会终止. 3.2 在嵌套if/else结构中,把最可能成立的条件放在该嵌套结构的开始处.和把不常见的条 ...
- OpenGL变换【转】
http://www.cnblogs.com/hefee/p/3811099.html OpenGL变换 概述 OpenGL变换矩阵 实例:GL_MODELVIEW矩阵 实例:GL_PROJECTIO ...
- [iOS 高级] iOS远程推送与本地推送大致流程
本地推送: UILocalNotification *notification=[[UILocalNotification alloc] init]; if (notification!=nil) { ...
- 【Android高级】NDK/JNI编程技术基础介绍
作为一个Andoird的Java程序猿,会受到Java语言的局限.由于作为一面门向对象的语言不能像C/C++那样轻易调用与硬件有关的操作.因此JNI就搭建了这样一个桥梁,使Java和C/C++语言之间 ...
- GridView后台绑定数据列表方法
在很多时候数据绑定都是知道了数据表中的表字段来绑定GridView控件的,那时候我就有个想法希望通过表明来查询数据库中的字段来动态的绑定GirdView控件数据并提供了相关的操作列,在网上找了一些资料 ...
- 【Excle数据透视表】如何禁用数据透视表的总计行/列
如上图:有行合计也有列合计.现在我们需要将行列合计都去除,如何操作呢? 解决办法一: 数据透视表区域任意单元格→数据透视表工具→设计→布局→总计→对行和列禁用 解决办法二: 数据透视表区域任意单元格→ ...