B - 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",(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 }

时间: 2024-08-26 04:30:01

B - Collective Mindsets (medium)的相关文章

A - Collective Mindsets (easy)

A - Collective Mindsets (easy) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u CodeForces 690A1 Description Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artf

[LeetCode] 011. Container With Most Water (Medium) (C++/Java/Python)

索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 011.Container_With_Most_Water (Medium) 链接: 题目:https://oj.leetcode.com/problems/container-with-most-water/ 代码(github):https://github.com/illuz/leetcode 题意: 给一些

[LeetCode] 012. Integer to Roman (Medium) (C++/Java/Python)

索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 012.Integer_to_Roman (Medium) 链接: 题目:https://oj.leetcode.com/problems/integer-to-roman/ 代码(github):https://github.com/illuz/leetcode 题意: 把十进制转为罗马数. 分析: 模拟即可.

medium and fine crushing

we series hydraulic cone crusher machine designed by our company is a new type of cone crusher machine with international advanced level which brings in Germanic technology.Ball Mill For Gold Our hydraulic cone crusher machine greatly increases the p

[LeetCode] 005. Longest Palindromic Substring (Medium) (C++/Java/Python)

索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 005.Longest_Palindromic_Substring (Medium) 链接: 题目:https://oj.leetcode.com/problems/Longest-Palindromic-Substring/ 代码(github):https://github.com/illuz/leetcode

Virtualbox - Fatal: Could not read from the boot medium; system halted!

刚装好的虚拟机系统,重新打开Virtualbox时出现个什么提示没认真看,顺势点了下去......结果虚拟机的xp系统打不开了,启动后出现:Fatal: Could not read from the boot medium; system halted! 按这个描述在网上百度.yahoo.bing,结果要放弃了时在google上找到这个: You haven't created a virtual hard disk. So your virtual machine is a machine

Developing a plugin framework in ASP.NET MVC with medium trust

http://shazwazza.com/post/Developing-a-plugin-framework-in-ASPNET-with-medium-trust.aspx January 7, 2011 10:06 Tweet I’ve recently spent quite a lot of time researching and prototyping different ways to create a plugin engine in ASP.NET MVC3 and prim

[LeetCode] 034. Search for a Range (Medium) (C++/Java)

索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 035. Search for a Range (Medium) 链接: 题目:https://leetcode.com/problems/search-for-a-range/ 代码(github):https://github.com/illuz/leetcode 题意: 在有序数组中找到一个数的范围.(由于数

[lintcode medium]Palindrome Linked List

Palindrome Linked List Implement a function to check if a linked list is a palindrome. Example Given 1->2->1, return true Challenge Could you do it in O(n) time and O(1) space? //// 1\find out the medium index of Linked list 2\ reverse the right par