Being a Good Boy in Spring Festival 尼姆博弈
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
Sample Output
Hint
Description
做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样。
话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的。比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情。如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题并不难,难的是全部做错,一个不对。
不幸的是,这种小概率事件又发生了,而且就在我们身边:
事情是这样的——HDU有个网名叫做8006的男性同学,结交网友无数,最近该同学玩起了浪漫,同时给n个网友每人写了一封信,这都没什么,要命的是,他竟然把所有的信都装错了信封!注意了,是全部装错哟!
现在的问题是:请大家帮可怜的8006同学计算一下,一共有多少种可能的错误方式呢?
Input
Output
Sample Input
2
3
Sample Output
1
2
Hint
Description
Input
Output
Sample Input
1
2
5
Sample Output
1
1
9
Hint
Description
A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into the hole every m holes. For example, m=2 and n=6, the wolf will get into the holes which are signed 0,2,4,0. If the rabbit hides in the hole which signed 1,3 or 5, she will survive. So we call these holes the safe holes.
Input
Output
Sample Input
2
1 2
2 2
Sample Output
NO
YES
Hint
Description
(a,b) can be easily found by the Euclidean algorithm. Now Carp is considering a little more difficult problem:
Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.
Input
Output
Sample Input
3
1 1
10 2
10000 72
Sample Output
1
6
260
Hint
Description
Do you want to challenge me? Just write your program to show your qualification!
Input
Output
Sample Input
4
2 1 2
0
1 3
0
1 0
2 0 2
0 4
1 1
1 2
0
0
2 0 1
2 1 1
3 0 1 3
0
Sample Output
WIN
WIN
WIN
LOSE
WIN
Hint
Description
Input
Output
Sample Input
2 1
8 4
4 7
Sample Output
0
1
0
Hint
Description
Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.
Input
The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.
Output
Output a blank line after each test case.
Sample Input
1 0 1 2 0 0
1 0 0 0 1 1
0 0 0 0 0 0
Sample Output
Collection #1:
Can't be divided. Collection #2:
Can be divided.
Hint
Description
But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs!
Input
Output
Sample Input
3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4
Sample Output
The minimum amount of money in the piggy-bank is 60.
The minimum amount of money in the piggy-bank is 100.
This is impossible.
Hint
Description
Therefore the German government requires a program for the following task:
Two politicians each enter their proposal of what to do. The computer then outputs the longest common subsequence of words that occurs in both proposals. As you can see, this is a totally fair compromise (after all, a common sequence of words is something what both people have in mind).
Your country needs this program, so your job is to write it for us.
Input
Each test case consists of two texts. Each text is given as a sequence of lower-case words, separated by whitespace, but with no punctuation. Words will be less than 30 characters long. Both texts will contain less than 100 words and will be terminated by a line containing a single '#'.
Input is terminated by end of file.
Output
Sample Input
die einkommen der landwirte
sind fuer die abgeordneten ein buch mit sieben siegeln
um dem abzuhelfen
muessen dringend alle subventionsgesetze verbessert werden
#
die steuern auf vermoegen und einkommen
sollten nach meinung der abgeordneten
nachdruecklich erhoben werden
dazu muessen die kontrollbefugnisse der finanzbehoerden
dringend verbessert werden
#
Sample Output
die einkommen der abgeordneten muessen dringend verbessert werden
Hint
Description
Input
Output
Sample Input
Sample Output
Hint
Description
Input
Output
Sample Input
Sample Output
Hint
Description
The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ?
Input
Followed by T cases , each case three lines , the first line contain two integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.
Output
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Sample Output
14
Hint
Description
春节回家 你能做几天好孩子吗
寒假里尝试做做下面的事情吧
陪妈妈逛一次菜场
悄悄给爸爸买个小礼物
主动地 强烈地 要求洗一次碗
某一天早起 给爸妈用心地做回早餐
如果愿意 你还可以和爸妈说
咱们玩个小游戏吧 ACM课上学的呢~
下面是一个二人小游戏:桌子上有M堆扑克牌;每堆牌的数量分别为Ni(i=1…M);两人轮流进行;每走一步可以任意选择一堆并取走其中的任意张牌;桌子上的扑克全部取光,则游戏结束;最后一次取牌的人为胜者。
现在我们不想研究到底先手为胜还是为负,我只想问大家:
——“先手的人如果想赢,第一步有几种选择呢?”
Input
Output
Sample Input
3
5 7 9
0
Sample Output
1
解题思路:尼姆博弈
尼姆博弈
尼姆博奕例子
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int m,ans,n,a[105];
while(scanf("%d",&m),m)
{
memset(a,0,sizeof(a));
n=ans=0;
for(int i=1;i<=m;i++)
{
scanf("%d",&a[i]);
n^=a[i]; } for(int i=1;i<=m;i++)
if((n^a[i])<a[i])
ans++;
if(ans)
printf("%d\n",ans);
else printf("0\n");
}
return 0;
}
Description
Input
Output
Sample Input
Sample Output
Hint
Description
做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样。
话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的。比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情。如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题并不难,难的是全部做错,一个不对。
不幸的是,这种小概率事件又发生了,而且就在我们身边:
事情是这样的——HDU有个网名叫做8006的男性同学,结交网友无数,最近该同学玩起了浪漫,同时给n个网友每人写了一封信,这都没什么,要命的是,他竟然把所有的信都装错了信封!注意了,是全部装错哟!
现在的问题是:请大家帮可怜的8006同学计算一下,一共有多少种可能的错误方式呢?
Input
Output
Sample Input
2
3
Sample Output
1
2
Hint
Description
Input
Output
Sample Input
1
2
5
Sample Output
1
1
9
Hint
Description
A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into the hole every m holes. For example, m=2 and n=6, the wolf will get into the holes which are signed 0,2,4,0. If the rabbit hides in the hole which signed 1,3 or 5, she will survive. So we call these holes the safe holes.
Input
Output
Sample Input
2
1 2
2 2
Sample Output
NO
YES
Hint
Description
(a,b) can be easily found by the Euclidean algorithm. Now Carp is considering a little more difficult problem:
Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.
Input
Output
Sample Input
3
1 1
10 2
10000 72
Sample Output
1
6
260
Hint
Description
Do you want to challenge me? Just write your program to show your qualification!
Input
Output
Sample Input
4
2 1 2
0
1 3
0
1 0
2 0 2
0 4
1 1
1 2
0
0
2 0 1
2 1 1
3 0 1 3
0
Sample Output
WIN
WIN
WIN
LOSE
WIN
Hint
Description
Input
Output
Sample Input
2 1
8 4
4 7
Sample Output
0
1
0
Hint
Description
Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.
Input
The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.
Output
Output a blank line after each test case.
Sample Input
1 0 1 2 0 0
1 0 0 0 1 1
0 0 0 0 0 0
Sample Output
Collection #1:
Can't be divided. Collection #2:
Can be divided.
Hint
Description
But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs!
Input
Output
Sample Input
3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4
Sample Output
The minimum amount of money in the piggy-bank is 60.
The minimum amount of money in the piggy-bank is 100.
This is impossible.
Hint
Description
Therefore the German government requires a program for the following task:
Two politicians each enter their proposal of what to do. The computer then outputs the longest common subsequence of words that occurs in both proposals. As you can see, this is a totally fair compromise (after all, a common sequence of words is something what both people have in mind).
Your country needs this program, so your job is to write it for us.
Input
Each test case consists of two texts. Each text is given as a sequence of lower-case words, separated by whitespace, but with no punctuation. Words will be less than 30 characters long. Both texts will contain less than 100 words and will be terminated by a line containing a single '#'.
Input is terminated by end of file.
Output
Sample Input
die einkommen der landwirte
sind fuer die abgeordneten ein buch mit sieben siegeln
um dem abzuhelfen
muessen dringend alle subventionsgesetze verbessert werden
#
die steuern auf vermoegen und einkommen
sollten nach meinung der abgeordneten
nachdruecklich erhoben werden
dazu muessen die kontrollbefugnisse der finanzbehoerden
dringend verbessert werden
#
Sample Output
die einkommen der abgeordneten muessen dringend verbessert werden
Hint
Description
Input
Output
Sample Input
Sample Output
Hint
Description
Input
Output
Sample Input
Sample Output
Hint
Description
The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ?
Input
Followed by T cases , each case three lines , the first line contain two integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.
Output
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Sample Output
14
Hint
Description
Input
Output
Sample Input
Sample Output
Hint
Description
做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样。
话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的。比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情。如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题并不难,难的是全部做错,一个不对。
不幸的是,这种小概率事件又发生了,而且就在我们身边:
事情是这样的——HDU有个网名叫做8006的男性同学,结交网友无数,最近该同学玩起了浪漫,同时给n个网友每人写了一封信,这都没什么,要命的是,他竟然把所有的信都装错了信封!注意了,是全部装错哟!
现在的问题是:请大家帮可怜的8006同学计算一下,一共有多少种可能的错误方式呢?
Input
Output
Sample Input
2
3
Sample Output
1
2
Hint
Description
Input
Output
Sample Input
1
2
5
Sample Output
1
1
9
Hint
Description
A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into the hole every m holes. For example, m=2 and n=6, the wolf will get into the holes which are signed 0,2,4,0. If the rabbit hides in the hole which signed 1,3 or 5, she will survive. So we call these holes the safe holes.
Input
Output
Sample Input
2
1 2
2 2
Sample Output
NO
YES
Hint
Description
(a,b) can be easily found by the Euclidean algorithm. Now Carp is considering a little more difficult problem:
Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.
Input
Output
Sample Input
3
1 1
10 2
10000 72
Sample Output
1
6
260
Hint
Description
Do you want to challenge me? Just write your program to show your qualification!
Input
Output
Sample Input
4
2 1 2
0
1 3
0
1 0
2 0 2
0 4
1 1
1 2
0
0
2 0 1
2 1 1
3 0 1 3
0
Sample Output
WIN
WIN
WIN
LOSE
WIN
Hint
Description
Input
Output
Sample Input
2 1
8 4
4 7
Sample Output
0
1
0
Hint
Description
Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.
Input
The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.
Output
Output a blank line after each test case.
Sample Input
1 0 1 2 0 0
1 0 0 0 1 1
0 0 0 0 0 0
Sample Output
Collection #1:
Can't be divided. Collection #2:
Can be divided.
Hint
Description
But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs!
Input
Output
Sample Input
3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4
Sample Output
The minimum amount of money in the piggy-bank is 60.
The minimum amount of money in the piggy-bank is 100.
This is impossible.
Hint
Description
Therefore the German government requires a program for the following task:
Two politicians each enter their proposal of what to do. The computer then outputs the longest common subsequence of words that occurs in both proposals. As you can see, this is a totally fair compromise (after all, a common sequence of words is something what both people have in mind).
Your country needs this program, so your job is to write it for us.
Input
Each test case consists of two texts. Each text is given as a sequence of lower-case words, separated by whitespace, but with no punctuation. Words will be less than 30 characters long. Both texts will contain less than 100 words and will be terminated by a line containing a single '#'.
Input is terminated by end of file.
Output
Sample Input
die einkommen der landwirte
sind fuer die abgeordneten ein buch mit sieben siegeln
um dem abzuhelfen
muessen dringend alle subventionsgesetze verbessert werden
#
die steuern auf vermoegen und einkommen
sollten nach meinung der abgeordneten
nachdruecklich erhoben werden
dazu muessen die kontrollbefugnisse der finanzbehoerden
dringend verbessert werden
#
Sample Output
die einkommen der abgeordneten muessen dringend verbessert werden
Hint
Description
Input
Output
Sample Input
Sample Output
Hint
Description
Input
Output
Sample Input
Sample Output
Hint
Description
The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ?
Input
Followed by T cases , each case three lines , the first line contain two integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.
Output
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Sample Output
14
Hint
Being a Good Boy in Spring Festival 尼姆博弈的更多相关文章
- Being a Good Boy in Spring Festival(尼姆博弈)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- Being a Good Boy in Spring Festival(杭电1850)(尼姆博弈)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- HDU.1850 being a good boy in spring festival (博弈论 尼姆博弈)
HDU.1850 Being a Good Boy in Spring Festival (博弈论 尼姆博弈) 题意分析 简单的nim 博弈 博弈论快速入门 代码总览 #include <bit ...
- 题解报告:hdu 1850 Being a Good Boy in Spring Festival(尼姆博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1850 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里 ...
- HDU1850 尼姆博弈求可行方案数目
尼姆博弈(Nimm's Game) 题型 尼姆博弈模型,大致上是这样的: 有3堆各若干个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取1个,多者不限,最后取光者得胜. 分析 1.首先自己想一下 ...
- hdu----(1849)Rabbit and Grass(简单的尼姆博弈)
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1849(Rabbit and Grass) 尼姆博弈
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)
Climbing the Hill Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Su ...
- Light OJ 1393 Crazy Calendar (尼姆博弈)
C - Crazy Calendar Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Su ...
随机推荐
- Md5 签名算法
/// <summary> /// MD5签名 /// </summary> /// <param name="pre ...
- 锋利的js之验证身份证号
我们在做互联网网站时,注册个人资料时,经常要用到身份证号,我们需要对身份证进验证,不然别人随便输个号码就通过,让你感觉这个网站做得很shit. 身份证号是有规则的. 结构和形式 1.号码的结构 公民 ...
- MySQL 第二篇
一.MySQL多实例介绍 mysql多实例,共用一套mysql安装程序,使用不同的配置文件(my.cnf).启动程序.和数据文件,即在一台服务器上同时开启多个不同的服务器端口(3306,3307),同 ...
- Makefile <网络转载>
陈皓 (CSDN)概述——什 么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和 professional的 ...
- 实例学习SQL的Select命令
1.查找员工的编号.姓名.部门和出生日期,如果出生日期为空值,--显示日期不详,并按部门排序输出,日期格式为yyyy-mm-dd.select emp_no ,emp_name ,dept ,isnu ...
- CheckedComboBoxEdit 重置初始化值的方法
CheckedComboBoxEdit ccbgb; ccbgb绑定方式ccbgb .Properties .DataSource =数据集; ccbgb.Properties.DisplayMemb ...
- Ogre 1.9 Android移植
Ogre 1.9 Android移植 分类: 图形渲染2013-02-04 16:47 3860人阅读 评论(14) 收藏 举报 Android Ogre C++linuxLinuxLINUX 上一篇 ...
- EMIF接口的寻址问题
2014年8月26日,一个网友提出了一个关于EMIF访问地址很典型的问题,在此我阐述一下我的个人理解. 一.提出问题 他问的问题没有这么简单,但是差不多就是这种意思,我在晚上找个典型事例,如下: DS ...
- JQuery 刷新关闭页面
关闭当前页面,刷新之前页面(js): window.opener.location.href = window.opener.location.href; window.close(); 刷新当前页面 ...
- 写css时要注意数字的浮动方向
写css时要注意数字的浮动方向 当数字位数增加时他的方向才是正确的 text-align:right;padding-right:29px;