【题目】

Description

A bunch of pirates have gotten their hands on a hoard of gold pieces and wish to divide the loot. They are democratic pirates in their own way, and it is their custom to make such divisions in the following manner: The fiercest pirate makes a proposal about the division, and everybody votes on it, including the proposer. If 50 percent or more are in favor, the proposal passes and is implemented forthwith. Otherwise the proposer is thrown overboard, and the procedure is repeated with the next fiercest pirate. 
All the pirates enjoy throwing one of their fellows overboard, but if given a choice they prefer cold, hard cash, the more the better. They dislike being thrown overboard themselves. All pirates are rational and know that the other pirates are also rational. Moreover, no two pirates are equally fierce, so there is a precise pecking order ― and it is known to them all. The gold pieces are indivisible, and arrangements to share pieces are not permitted, because no pirate trusts his fellows to stick to such an arrangement. It's every man for himself. Another thing about pirates is that they are realistic. They believe 'a bird in the hand is worth two in the bush' which means they prefer something that is certain than take a risk to get more, where they might lose everything.

For convenience, number the pirates in order of meekness, so that the least fierce is number 1, the next least fierce number 2 and so on. The fiercest pirate thus gets the biggest number, and proposals proceed in the order from the biggest to the least.

The secret to analyzing all such games of strategy is to work backward from the end. The place to start is the point at which the game gets down to just two pirates, P1 and P2. Then add in pirate P3, P4, ... , one by one. The illustration shows the results when 3, 4 or 5 pirates try to divide 100 pieces of gold.

Your task is to predict how many gold pieces a given pirate will get.

Input

The input consists of a line specifying the number of testcases, followed by one line per case with 3 integer numbers n, m, p. n (1 ≤ n ≤ 10^4) is the number of pirates. m (1 ≤ m ≤ 10^7) is the number of gold pieces. p (1 ≤ p ≤ n) indicates a pirate where p = n indicates the fiercest one. 

Output

The output for each case consists of a single integer which is the minimal number of gold pieces pirate p can get. For example, if pirate p can get 0 or 1 gold pieces, output '0'. If pirate p will be thrown overboard, output 'Thrown'. 

Sample Input

3
3 100 2
4 100 2
5 100 5

Sample Output

0
1
98
 
 
【题意】
  这是一个经典问题,有n个海盗,分m块金子,其中他们会按一定的顺序提出自己的分配方案,如果50%以上的人赞成,则方案通过,开始分金子,如果不通过,则把提出方案的扔到海里,下一个人继续。
 
【分析】
 
  自己先从小到大玩一遍这个游戏,就能找到一些规律。

  分够贿赂和不够贿赂两种情况。抓特点:一个人如果将要死,他会支持前面的人保证自己不死。如果能得到更多的钱,他会更加支持。如果得到同样的钱,他乐于把前面的人扔下水。对于

够钱贿赂的情况,他会给与自己同奇偶的人。这样票数也够,他也会支持你。(具体为什么思考一下就知道了)。对于不够钱贿赂,要考虑到人不希望死这个情况,找到规律,决策者总是

2*m+2^k(k为任意整数),可是他具体贿赂谁是不确定的,所以除了一些在前面的必死的人,其他人的ans都为0。

  具体看大神blog:http://blog.csdn.net/acm_cxlove/article/details/7853916

代码如下:

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 1010 void ffind(int x,int y,int z)
{
if(x<=*y+)
{
if(z==x) printf("%d\n",y-(x-)/);
else if((x-z)%==) printf("1\n");
else printf("0\n");
}
else
{
int mx;
for(int i=;(*y)+(<<i)<=x;i++) mx=*y+(<<i);
if(z>mx) printf("Thrown\n");
else printf("0\n");
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m,p;
scanf("%d%d%d",&n,&m,&p);
ffind(n,m,p);
}
return ;
}

[HDU1538]

2016-04-25 13:21:52

【HDU1538】A Puzzle for Pirates(经典的海盗问题)的更多相关文章

  1. 【 HDU 1538 】A Puzzle for Pirates (海盗博弈论)

    BUPT2017 wintertraining(15) #5D HDU 1538 偷懒直接放个果壳的链接了,感觉比网上直接找这题的题解要更正确.易懂. 海盗博弈论 代码 #include <cs ...

  2. hdu 1538 A Puzzle for Pirates 博弈论

    很经典的问题,思路转载自http://blog.csdn.net/ACM_cxlove?viewmode=contents 题目:这是一个经典问题,有n个海盗,分m块金子,其中他们会按一定的顺序提出自 ...

  3. 博弈论BOSS

    基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...

  4. 【Mark】博弈类题目小结(HDU,POJ,ZOJ)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...

  5. 黑帆第一季/全集Black Sails迅雷下载

    黑帆 第一季 Black Sails Season 1 (2014)本季看点:剧集将会是英国小说家罗伯特·路易斯·史蒂文森(Robert Louis Stevenson)经典的海盗故事<金银岛& ...

  6. LeetCode(51) N-Queens

    题目 The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two quee ...

  7. POJ 3678 Katu Puzzle (经典2-Sat)

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6553   Accepted: 2401 Descr ...

  8. 浙大PAT 2-10. 海盗分赃——经典博弈

    题意 P个海盗偷了D颗钻石后分赃($3 \leq P, D\leq 100$),采用分赃策略: 从1号开始,提出一个分配金币的方案,如果能够得到包括1号在内的绝对多数(即大于半数)同意,则执行该方案, ...

  9. ZOJ 3541 The Last Puzzle(经典区间dp)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3541 题意:有一排开关,有个开关有两个值t和d,t是按下开关后在t秒后会自 ...

随机推荐

  1. HTTP的报文格式,GET和POST的区别

    1.HTTP报文格式 HTTP报文是面向文本的,报文中的每一个字段都是一些ASCII码串,各个字段的长度是不确定的.HTTP有两类报文:请求报文和响应报文. 请求报文: 一个HTTP请求报文由请求行( ...

  2. RTB日志分析MR程序设计

    到新公司三个月了,上个月做的是Beacon项目,详细的设计思想还没有写文档.这两周开始搞Hadoop,开始阅读相关论文.开始编写MR程序.开始写java,大学时用java较多,工作后就一直在用c/c+ ...

  3. myeclipse2014新感悟

    部署有两种方式:1.直接把文件拷贝到 tomcat下的webroot文件夹下 2.myeclipse软件内部点击“deploy”部署 →点击add→tomcat下的webroot文件夹下 点击完“运行 ...

  4. asp.net ueditor 图片上传路径问题解决

    最近练习做一个新闻系统,其中不能少了添加新闻和修改新闻的功能 ,而且还要添加图片.添加文字样式, 所以不得不使用富文本编辑器,在kindeditor和ueditor中,选择了目前还在持续更新的百度产品 ...

  5. 在后台CS文件里面,隐藏和显示Repeater里面控件

    <asp:Repeater ID="Repeater1" runat="server"><ItemTemplate><asp:Pa ...

  6. JavaScript小笔记の经典算法等....

    1.利用toString()里面的参数,实现各进制之间的快速转换: var n = 17; binary_string = n.toString(2); //->二进制"10001&q ...

  7. Java-Junit 的Hello world

    这里介绍junit 4的基本配置: <1>建立一个java project项目. <2>在src目录下面建一个包,com.sun.junit4,在包下面写一点文件T.java ...

  8. WindowsServer2003SP2EnterpriseEdition在Virtual上的安装

    下载镜像(迅雷): http://192.168.0.101/WindowsServer2003SP2EnterpriseEdition.iso?fid=fWljwnwNgumTtRIy- *BY*a ...

  9. 为什么用linear regression可以做classification

    输出空间 错误衡量方式 能不能直接用linear regression for classification 当成一个分类器回传回去 heuristic(启发式的:试探) 错误衡量 complexit ...

  10. 日期-用Datapicker实现前一天后一天

    运用了JQuery UI Datepicker 插件和一些常用日期的方法.其中Datepicker的API具体可参考[http://api.jqueryui.com/datepicker/#optio ...