zoukankan      html  css  js  c++  java
  • Collective Mindsets (medium) (逻辑题)

    B - Collective Mindsets (medium)

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    CodeForces 690A2

    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

    Input
    1
    Output
    0
    Input
    3
    Output
    1
    Input
    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-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-m)/2);
    15         }
    16     }
    17     return 0;
    18 }
    View Code
  • 相关阅读:
    css
    10个顶级的CSS和Javascript动画框架推荐
    js格式化时间(自己修改并注释)
    分享一篇获取键盘数值的js(限制在IE浏览器)
    Myeclipse一个设置小技巧,加速编码提示。
    悲剧的代码工
    Log4j与commonlogging
    没有人的了
    不想被淘汰,就别做这八种人!
    MVN 资料一
  • 原文地址:https://www.cnblogs.com/haoabcd2010/p/5924914.html
Copyright © 2011-2022 走看看