【题目】

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. 使用Broadcast实现android组件之间的通信 分类: android 学习笔记 2015-07-09 14:16 110人阅读 评论(0) 收藏

    android组件之间的通信有多种实现方式,Broadcast就是其中一种.在activity和fragment之间的通信,broadcast用的更多本文以一个activity为例. 效果如图: 布局 ...

  2. WGS84经纬度坐标与web墨卡托之间的转换【转】

    第一种方法: //经纬度转Web墨卡托 dvec3 CMathEngine::lonLat2WebMercator(dvec3 lonLat) { dvec3 mercator; ; ); ; mer ...

  3. .net+easyui系列--搜索框

    <input id="ss" style="width: 320px"> </input> <div id="mm&qu ...

  4. 避免 TCP/IP 端口耗尽

    转载:http://www.cnblogs.com/tianzhiliang/archive/2011/06/27/2091214.html 当客户端启动到服务器的 TCP/IP 套接字连接时,客户端 ...

  5. CALayer 认识

    一篇很好的讲述calayer的博客 http://www.cnblogs.com/kenshincui/p/3972100.html

  6. 小白偶遇Sublime Text 3

    sublime text3号称神一样的编辑器,主要归功于它丰富的插件所带来的可扩展性.以前曾经抱着玩一玩的心态下载了sublime ,没有插件的sublime 很快被我扔到一边.在用过很多的编辑器后, ...

  7. label语句和break continue的使用(高程第三章)

    break&&outermost var num = 0; outermost: for(var i=0;i<10;i++){ for(var j=0;j<10;j++){ ...

  8. C++类型转换总结 转

    一.前言: C风格的强制类型转换(Type Cast)很简单,不管什么类型的转换统统是: TYPE b = (TYPE)a. C++风格的类型转换提供了4种类型转换操作符来应对不同场合的应用. con ...

  9. 判断IE浏览器用IE条件表达式

    <!--[if IE]> <script type="text/javascript"> alert("ie") </script ...

  10. 18款js和jquery文字特效代码分享

    18款js和jquery文字特效代码分享 jQCloud标签云插件_热门城市文字标签云代码 js 3d标签云特效关键词文字球状标签云代码 原生JS鼠标悬停文字球状放大显示效果代码 原生js文字动画圆形 ...