B - Collective Mindsets (medium)
Posted happy_code
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了B - Collective Mindsets (medium)相关的知识,希望对你有一定的参考价值。
B - Collective Mindsets (medium)
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 ≤ N ≤ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Sample Input
1
0
3
1
99
Output
49
有 n - 1 个僵尸,1 个是主角 hedi ,他们在一起分大脑。。。n 个人都是有个独特的等级的,让等级最高的人来决定分配大脑的方案,如果没有至少半数的僵尸同意,等级最高的就会死,让低一个等级的僵尸去决定分配方案,如此分直到有至少半数僵尸同意,僵尸是非常狡猾的,且非常聪明,他们怕死,但在不死的前提下想获得更多的大脑。现在heidi是等级最高的,他自己不想拿大脑了,只想活下去,问最少需要多少大脑。
//这题我就是推出16项,然后就看出规律了。。。这么去考虑:
如果只有一个人,0个就可以,大于0个也可以走
如果有两个人,0个就可以走,大于0个自己拿也可以走
如果有三个人,必须给1个给 1 ,不然自己就要死,大于1个都可以自己拿
如果有四个人,0个就可以了,因为 3 要同意,因为 3 只有0个也要死,所以只能同意,4同意自己,ok,如果有 1 个,必须拿去贿赂 2 ,才能活命,大于2就能自己拿了。
以此类推,推到16就看出规律了。。。
1 #include<stdio.h> 2 int main() 3 { 4 int n; 5 while (scanf("%d",&n)!=EOF) 6 { 7 if (n%2) 8 printf("%d\\n",(n-1)/2); 9 else 10 { 11 int m=2; 12 while(m<n) m*=2; 13 if (m>n) m/=2; 14 printf("%d\\n",(n-m)/2); 15 } 16 } 17 return 0; 18 }
以上是关于B - Collective Mindsets (medium)的主要内容,如果未能解决你的问题,请参考以下文章
深度学习分布式训练Collective通信操作及Pytorch示例
Collective Production Orders in PP
如何在 Laravel 5.7 和 Laravel Collective 中使用动作 [重复]
使用 Laravel Collective、Bootstrap 模型和 JavaScript 的客户端表单验证和路由?
HGsuspector: Scalable Collective Fraud Detection in Heterogeneous Graphs