HDU 1538 - A Puzzle for Pirates(海盗分金)

HDU 1538 A Puzzle for Pirates(经典的海盗分金推理) 转载请注明出处,谢谢 http://blog.youkuaiyun.com/ACM_cxlove?viewmode=contents           by---cxlove 题目:这是一个经典问题,有n个海盗,分m块金子,其中他们会按一定的顺序提出自己的分配方案,如果50%以上的人赞成,则方案通过,开始分金子,如果不通过,则把提出方案的扔到海里,下一个人继续。 http://acm.hdu.edu 阅读详情

A Puzzle for Pirates

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 198    Accepted Submission(s): 60


Problem 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
Hint
Hint
The situation gets complicated when a few gold pieces were divided among many pirates.
 


====================================


#include <iostream>
#include <cstdio>

using namespace std;

int n,m,p,ans;
int f[15]={2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384};

int deal()
{
    if(n<=m*2+1)
    {
        if(p==n)
        {
            ans=m-(n-1)/2;
        }
        else
        {
            if((p%2)^(n%2))
                ans=0;
            else
                ans=1;
        }
        return ans;
    }
    else
    {
        int temp=n-m*2;
        for(int i=0;i<14;i++)
        {
            if(temp==f[i])
            {
                ans=0;
                return ans;
            }
        }
        for(int i=0;i<14;i++)
        {
            if(temp<f[i])
            {
                if(p>2*m+f[i-1])
                    ans=-1;
                else
                    ans=0;
                return ans;
            }
        }
    }
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&m,&p);
        deal();
        if(ans==-1)
            puts("Thrown");
        else
            printf("%d\n",ans);
    }
    return 0;
}


『杭电1538』A Puzzle for Pirates Problem 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 阅读详情

相关推荐

STM32--LoRa通信模块

模块根据MD0的配置与AUX引脚的状态会进入不同的功能其中在通信功能下,包含4种工作模式。

qq_47258284的博客 1万+

[益智]:海盗分赃(博弈论的实用)

海盗分赃问题描述:问题分析:以动漫理解这个问题正确解答:题目升级:正确思路现实生活中这种问题还有哪些变化呢?下面给大家分享一个关于金币的小游戏 问题描述:   三个极其聪明的海盗抢到100枚硬币,每一颗宝石都一样大小和价值连城。他们决定以抽签投票的方式来分配这些宝石:有(1、2、3)三个号码,每人抽取一个。首先,由1号提出分配方案,然后大家举手表决,当且仅当超过半数的人同意时,按照他的分配方案 进行分配,否则将被扔进海里喂鲨鱼。如果1号死后,再由2号提出分配方案,规则如前所述,以此类推。 问:第一个海盗提

AngelDg的博客 4276

一种导弹追踪算法的MATLAB仿真实现

以下是一个用于模拟机动变轨导弹和防空导弹追踪过程的 MATLAB 代码,同时会提供 3D 效果展示。你可以运行这段代码,从而观察机动变轨导弹和防空导弹的速度与位置变化。

SmartGridequation的博客 933

五个强盗分金币的问题分析(博弈论)

话说五个强盗抢得100枚金币,他们决定: 1、抽签决定各人的号码(1,2,3,4,5 );2、由1号提出分配方案,然后5人表决,当且仅当超过半数同意方案被通过,否则他将被扔入大海喂鲨鱼;3、1号死后,由2号提方案,4人表决,当且仅当超过半数同意时案通过,否则2号同样被扔入大海;4、依次类推…… 假定“每个海盗都是很聪明的人,都能很理智的判断得失,从而做出选择”,那么“第一个海盗提出怎样的分配方

8898

【R语言-生存分析之观察生存率计算】

全人群肿瘤登记资料常用的统计分析指标包括发病率、死亡率、现患率以及生存率等,其中肿瘤生存率是评估肿瘤治疗效果和肿瘤负担的必要指标,其计算涉及肿瘤患者的发病、 死亡和随访三个方面的资料, 数据整理和计算过程均较为复杂, 如何及时、 准确地计算肿瘤生存率, 并使其可以在不同地区、 不同人群、不同时期间被客观公正地比较和评价,仍然是统计学家们一直在研究的主题。

weixin_46579654的博客 5440

拖动无标题栏的cef3窗口

拖动嵌入了cef3的无标题栏win32窗口,本质上就是拖动子窗口移动父窗口这么个事情,这个在自己创建窗口的程序上处理非常简单,cef封装较多,想修改的完善点步骤较多。         cef所用版本3.2623。         就用cefclient来做测试工程,首先建议在cefclient_win.cc的RunMain函数中的app = new ClientAppRenderer();前面

loveyong1990的专栏 6161

hdu1538博弈论-海盗分金-博弈入门

0)觉得博弈游戏蛮有意思的,这算是第一个题把。 1)AC代码。 思路,对于每一个海盗来说,优先性由高到低依次为,保命,得金,杀人。所以可能为了保命、得金、杀更多人而支持或反对决策者。第一种情况时,金子足够,第二种是金子不够、决策者自己不要金子去贿赂别人而保住命且没有人会死,第三种情况是金子不够、决策者不要金子去贿赂别人但依然会死,支持他的人(不支持自己也是必死)也可能会死。 #include

他的博客 1415

【FPGA教程案例96】控制案例1——基于FPGA的自适应PID控制器verilog实现

首先,我们复习下课程传统的PID控制器,往往存在调整速度较慢,超调过大等缺点。为了解决这个问题,在实际的PID应用中,需要实时的调整PID的控制参数,以达到加快PID控制速度,降低超调等目标。目前,自适应PID控制器,一般有误差反馈调整,模糊控制器调整,神经网络调整。其中模糊控制器调整,神经网络调整较为复杂,在入门案例中不做介绍,在本课程中,我们将实现相对略微简单点的基于误差反馈调整的自适应PID控制器。

FPGA/MATLAB学习教程/源码/项目合作开发 6203

hdu-1538 A Puzzle for Pirates

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1538 题目类型: 模拟 题意概括: 有1~n,n个海盗,m块金子,第n个海盗要提出一个分金方案,如果有一半以上的人同意,就立刻分金,反之就将这个人扔下水里,问所有情况都是最优解的情况下,要给第p个海盗分多少金? 解题思路: 如果只有一个人,所以肯定是给自己。 如果有两个人,那么自己将...

weixin_30394633的博客 197

8、对比 LightGBM、XGBoost 和深度学习

本文对比了LightGBM、XGBoost和深度学习模型(特别是TabTransformer)在处理表格数据时的性能差异。从模型复杂度、数据准备、训练时间、准确性和适用场景等方面进行分析,重点探讨了三者在人口普查收入预测任务中的表现。文章详细介绍了XGBoost与LightGBM的核心特性与区别,深入讲解了TabTransformer的架构与实现,并涵盖了分类特征编码、缺失值处理和类别不平衡等关键数据预处理技术,为选择合适的表格数据建模方法提供了实践指导。

julia4scientist的博客 120

vue支付项目-APP支付宝支付功能

如果用户已安装支付宝客户端,商家 App 唤起支付宝完成支付,支付完后跳回到商家 App 内,最后展示支付结果。如果用户没有安装支付宝客户端,商家 App 内会调起支付宝网页支付收银台,用户登录支付宝账号,支付完后展示支付结果。1.点击按钮开通或者续费,会验证是否选择会员商品以及对协议是否查看选中(这里根据项目需要自行验证,可忽略),验证通过打开选择支付方式弹窗页面,选择微信支付或者支付宝支付;4.可取消支付,放弃支付会返回会员页面,页面提示支付取消;1.判断支付方式,如果是2,则是支付宝支付方式。

总结前端开发中遇到的问题,分享前端知识 1万+

HDU 1538 A Puzzle for Pirates 海盗分金问题

题目大意: 就是现在n个海盗分配m枚金币, 依次编号为P1~Pn 然后海盗按照Pn->P(n - 1)->...->P2->P1的顺序提出分配方案, 然后或者的海盗投票表示是否赞成这个方案, 提出方案的海盗也会参与投票, 如果有一半或者以上的海盗赞成, 那么这个方案就通过, 按照这个方案分配金币, 否则这个海盗会被扔进海里喂鲨鱼, 各个海盗都决定聪明并且想使得自己的利益最大化, 当然这里各个海

Gatevin的专栏 913

使用 Visual Studio Code 连接 ABAP On-Premise 系统做开发的详细配置步骤

本文详细介绍了如何在Visual Studio Code中通过ABAP Development Tools扩展连接ABAP On-Premise系统。关键步骤包括:通过Ctrl+Shift+P打开命令行面板选择「ABAP: New Destination...」创建RFC连接(仅支持SSO单点登录),选择本地SAPGUI中已有的系统,输入Client ID、语言和用户名(无需密码),最后将目标系统添加到工作区即可开始开发。文章强调了企业安全考虑下仅支持SSO的设计理念,并展示了连接配置的JSON格式示例。整

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 987

hdu1538 A Puzzle for Pirates---海盗分金---博弈

A Puzzle for Pirates Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 141    Accepted Submission(s): 32 Problem Description A bunch of p

Shirley 2572

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

HDU - 1538 A Puzzle for Pirates 海盗分金

题目:有n个海盗,分m块金子,其中他们会按一定的顺序提出自己的分配方案,如果50%以上的人赞成,则方案通过,开始分金子,如果不通过,则把提出方案的扔到海里,下一个人继续。从第n个人开始决策,问第p个人能分多少金子,或是被扔到海里 思路: 参考http://blog.youkuaiyun.com/acm_cxlove/article/details/7853916  的博客做出来的,写的很详细 代码:

ACVevtor的博客 521

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

HDU 1538 A Puzzle for Pirates (海盗分金问题)

A Puzzle for Pirates Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 508Accepted Submission(s): 167 Problem Description A bunch of p...

169

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

hdu_oj1538A Puzzle for Pirates(海盗分金)

这道题目确实很难,特判的情况很多,参考了大神的题解才AC掉http://blog.youkuaiyun.com/ACM_cxlove?viewmode=contents by---cxlove 题目:这是一个经典问题,有n个海盗,分m块金子,其中他们会按一定的顺序提出自己的分配方案,如果50%以上的人赞成,则方案通过,开始分金子,如果不通过,则把提出方案的扔到海里,下一个人继续。 首先我们讲一下海盗分金决策的三个标准:保命,拿更多的金子,杀人,优先级是递减的。 同时分为两个状态...

_C9的博客 371

HDU 1538 A Puzzle for Pirates(海盗分金问题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1538 题意:有n个海盗,分m块金子,从第n个海盗开始,依次提出自己的分配方案,如果50%以上的人赞成,则方案通过,开始分金子,如果不通过,则把提出方案的扔到海里,下一个人继续。问编号为p的人最多分得多少金子? 思路:以下是cxlove的思路:如果只有两个人的话那么2号开始提出方案,这时候2号知道不...

weixin_33869377的博客 235

[海盗分金] HDU 1538 A Puzzle for Pirates

久闻大名的海盗分金问题 详见HDU 1538 A Puzzle for Pirates(经典的海盗分金推理)#include<cstdio> #include<cstdlib> #include<algorithm> #define read(x) scanf("%d",&(x)) using namespace std;int fac[]={1,2,4,8,16,32,64,128,256,51

雯舞 489

hdu 1538 A Puzzle for Pirates (海盗分金问题)

A Puzzle for Pirates Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 884    Accepted Submission(s): 337 Problem Description A bunch of

clover_hxy的博客 672

HDU 1538 A Puzzle for Pirates(经典好题,海盗分金问题)

A Puzzle for Pirate   HDU - 1538   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

Eiffel的博客 813

HDU1538——A Puzzle for Pirates(博弈论,海盗分金问题)

A Puzzle for Pirates Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 911    Accepted Submission(s): 351 Problem Description A bunch

say_c_box的博客 689
上一篇: HDU 1517 - A Multiplication Game
下一篇: HDU 3032 - Nim or not Nim?(SG)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值