【HDU1538】A Puzzle for Pirates(经典的海盗问题)
【题目】
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 5Sample Output
0
1
98
分够贿赂和不够贿赂两种情况。抓特点:一个人如果将要死,他会支持前面的人保证自己不死。如果能得到更多的钱,他会更加支持。如果得到同样的钱,他乐于把前面的人扔下水。对于
够钱贿赂的情况,他会给与自己同奇偶的人。这样票数也够,他也会支持你。(具体为什么思考一下就知道了)。对于不够钱贿赂,要考虑到人不希望死这个情况,找到规律,决策者总是
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(经典的海盗问题)的更多相关文章
- 【 HDU 1538 】A Puzzle for Pirates (海盗博弈论)
BUPT2017 wintertraining(15) #5D HDU 1538 偷懒直接放个果壳的链接了,感觉比网上直接找这题的题解要更正确.易懂. 海盗博弈论 代码 #include <cs ...
- hdu 1538 A Puzzle for Pirates 博弈论
很经典的问题,思路转载自http://blog.csdn.net/ACM_cxlove?viewmode=contents 题目:这是一个经典问题,有n个海盗,分m块金子,其中他们会按一定的顺序提出自 ...
- 博弈论BOSS
基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...
- 【Mark】博弈类题目小结(HDU,POJ,ZOJ)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...
- 黑帆第一季/全集Black Sails迅雷下载
黑帆 第一季 Black Sails Season 1 (2014)本季看点:剧集将会是英国小说家罗伯特·路易斯·史蒂文森(Robert Louis Stevenson)经典的海盗故事<金银岛& ...
- 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 ...
- POJ 3678 Katu Puzzle (经典2-Sat)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6553 Accepted: 2401 Descr ...
- 浙大PAT 2-10. 海盗分赃——经典博弈
题意 P个海盗偷了D颗钻石后分赃($3 \leq P, D\leq 100$),采用分赃策略: 从1号开始,提出一个分配金币的方案,如果能够得到包括1号在内的绝对多数(即大于半数)同意,则执行该方案, ...
- ZOJ 3541 The Last Puzzle(经典区间dp)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3541 题意:有一排开关,有个开关有两个值t和d,t是按下开关后在t秒后会自 ...
随机推荐
- activity-intent-startActivity-startActivityResult
一. Intent和startActivity 1.在一个Activtiy中可以使用startActivity()去开始另一个制定的Activity 但在android3.0(是针对平板出的产品)之后 ...
- WSDL阅读方法
我们以天气预报WebService服务为例,来看看怎么阅读一个wsdl文档. 打开一个wsdl文档后,先看底部. binding在这里: portType在这里: 好了,看了上面的,我们来说说wsdl ...
- Eclipse优化集合,Eclipse优化速度,解决Ctrl+C、Ctrl+V卡
Eclipse优化集合,Eclipse优化速度,解决Ctrl+C.Ctrl+V卡 >>>>>>>>>>>>>>> ...
- readonly时禁用删除键,readonly按删除键后页面后退解决方案
readonly时禁用删除键, readonly按删除键后页面后退解决方案 >>>>>>>>>>>>>>>&g ...
- HDU-1015(暴力)
Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is loc ...
- Asp.net Mvc对比Php的4大误解
一:asp.net技术已过时,Php技术更新 Asp.net mvc 5 发布于2014 夏天. 二:php开发者更多,所以更能得到帮助 2者对比犹如下图,会拿电锯的肯定多少会点锯子, 会用锯子的不一 ...
- [GDI+] 生成缩略图的类文件SmallImage (转载)
直接看代码吧,大家可以直接复制使用 /// <summary> /// 类说明:SmallImage类, /// 编码日期:2012-08-20 /// 编 码 人: 苏飞 /// 联系方 ...
- python中文件类的应用
python中对文件.文件夹的操作需要涉及到os模块和shutil模块. 创建文件: 1) os.mknod("test.txt") 创建空文件 2) open("tes ...
- Java 读取Properties 配置文件
方法一,使用 io 包中的 BufferedInputStream 以及 FileInputStream读入文件转成字符流,然后使用 lang 包中 的 Properties 的 load 方法进行读 ...
- spring boot 中文文档翻译地址
https://github.com/qibaoguang/Spring-Boot-Reference-Guide/blob/master/SUMMARY.md