【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秒后会自 ...
随机推荐
- PureMVC(JS版)源码解析(十一):Model类
这篇博文讲PureMVC三个核心类——Model类.Model类的构造函数及工厂函数[即getInstance()方法]和View类.Controller类是一样的,这里就不重复讲解了,只 ...
- SDWebImage 原理及使用
这个类库提供一个UIImageView类别以支持加载来自网络的远程图片.具有缓存管理.异步下载.同一个URL下载次数控制和优化等特征. SDWebImage 加载图片的流程 入口 setImageWi ...
- nginx同时监听本机ipv4/ipv6端口
修改nginx.conf配置文件 server { listen ; listen [::]:; } 0.0.0.0 表示本机所有ipv4地址,需要监听特定地址替换即可 [::] 表示本机所有ip ...
- asp.net页面刷新等问题
windows.open 关闭当前页面刷新父页面实现() { 在子页面中 Page.ClientScript.RegisterStartupScript(this.GetType(), "a ...
- gulp 初体验
1,全局安装 gulp npm install --global gulp 但是一直无法成功,后来才知被墙了,于是使用了如下命令,安装cnpm npm install -g cnpm --regist ...
- Spring JdbcTemplate批量操作数据库
个人总结,转载请注明出处:http://www.cnblogs.com/lidabnu/p/5769732.html 还是分两部分:解决什么问题和怎么做. 解决什么问题 提升数据操作性能,因为批量操作 ...
- Andriod ADT v22.6.2版本中在Mainactivity.java中使用fragment_main.xml中TextView控件对象的问题
众所周知,我们既可以在 activity_main.xml文件中控制activity中的view,也可以使用java代码的set..()方法控制它.在学习过程中,发现在ADT新版本中,和以前版本有区别 ...
- 基于shiro授权过程
1.对subject进行授权,调用方法isPermitted("permission串")2.SecurityManager执行授权,通过ModularRealmAuthorize ...
- Apache虚拟目录
Apache虚拟目录 1.打开Apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#! 2.在httpd.conf 末尾 ...
- OC基础-day02
#pragma mark - Day02_01_对象的创建与使用 1)如何通过类创建一个对象 1. 类是抽象的,无法直接使用 2. 对象是类的一个具体实现,可以直接使用 3. 语法 类名 *对象名 = ...