Champion of the Swordsmanship


Time Limit: 2 Seconds      Memory Limit: 65536 KB

In Zhejiang University, there is a famous BBS named Freecity. Usually we call it 88.

Recently some students at the Humour board on 88 create a new game - Swordsmanship. Different from the common sword fights, this game can be held with three players playing together in a match. Only one player advances from the match while the other two are eliminated. Sometimes they also hold a two-player match if needed, but they always try to hold the tournament with as less matches as possible.

Input

The input contains several test cases. Each case is specified by one positive integer n (0 < n < 1000000000), indicating the number of players. Input is terminated by n=0.

Output

For each test case, output a single line with the least number of matches needed to decide the champion.

Sample Input

3
4
0

Sample Output

1
2

思路:抽象化。假如有n个人,最少需要比赛f(n)次,为了最少,肯定3个3个一组比赛,这需要n/3次,接下来除去淘汰的,还剩下n/3 + n % 3个人,这时需要比赛f(n/3 + n%3)次,那么f(n) = n / 3 + f(n /3 + n%3).如n == 1,则需要进行0次,n == 2需要进行1次。

显然用递归就解决啦。

 #include <iostream>
using namespace std;
int func(int n){
if(n == )
return ;
if(n == )
return ;
return n / + func(n / + n % );
} int main(){
int n;
while(cin >> n){
if(n == )
break;
cout << func(n) << endl;
}
return ;
}

zoj 2830 Champion of the Swordsmanship的更多相关文章

  1. 1653: Champion of the Swordsmanship

    1653: Champion of the Swordsmanship Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 11  Solved: 8[Subm ...

  2. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  3. AC日记——蓬莱山辉夜 codevs 2830

    2830 蓬莱山辉夜  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 在幻想乡中,蓬莱山辉夜是月球 ...

  4. codevs 2830 蓬莱山辉夜

    2830 蓬莱山辉夜 http://codevs.cn/problem/2830/ 题目描述 Description 在幻想乡中,蓬莱山辉夜是月球公主,居住在永远亭上,二次设定说她成天宅在家里玩电脑, ...

  5. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  6. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  7. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  8. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  9. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

随机推荐

  1. android开发学习 ------- debug 和 release版本执行结果不同

    在debug上测试成功的,release上测试不成功,就想着怎么将 release 版本进行调试一下.还好 Android Studio 3.0是可以进行调试apk的 可以显示log,自己看自己的逻辑 ...

  2. 解决win64无法添加curl扩展的问题

    网上试了很多方法都无效,最后直接用phpstudy集成安装包中对应版本的php_curl.dll替换即可

  3. chrome浏览器之网络面板

    这篇指导向你展示怎样检测网络张状况或者在chrome开发工具的网络面板中尽可能的优化网页. 排列的或受阻的请求 症状:同时发出六个请求.之后有一系列的请求排队或受阻.一旦最先的六个请求中有一个响应结束 ...

  4. Spark-水库抽样-根据抽样率确定每个分区的样本大小

    /* * 输入:采样率,待采样的RDD * 输出:每个分区的样本大小(记录数) * 由采样率确定,每个分区的样本大小 */ def findNumPerPartition[T: ClassTag, U ...

  5. iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译

    编号 iOS-Apple苹果官方文档翻译名称 博文链接地址 1 苹果API常用英语名词---iOS-Apple苹果官方文档翻译 http://www.cnblogs.com/ChenYilong/p/ ...

  6. ARC和MRC混合模式下的编译问题

    在一个支持ARC (Automatic Reference Counting)的项目中,有时候需要禁止其中几个文件使用ARC模式编译(比如你用了第三方不支持ARC的类库).这时就要点击工程文件,在ta ...

  7. Codeforces Round #318 (Div. 2) A Bear and Elections (优先队列模拟,水题)

    优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main( ...

  8. feature map计算大小公式

    http://blog.csdn.net/cheese_pop/article/details/51955915 将整个分成两部分,左边部分,右边部分.右边部分每次其实都是移动stride这么大,左边 ...

  9. Sublime Text 套件介紹(四):Pretty JSON

    JSON,一個輕量級的資料交換語言,目前許多網站AJAX request的回應結果都是JSON格式   以下是一個標準的JSON格式   { "firstName": " ...

  10. Codeforces Round #271 (Div. 2)-A. Keyboard

    http://codeforces.com/problemset/problem/474/A A. Keyboard time limit per test 2 seconds memory limi ...