zoj 2830 Champion of the Swordsmanship
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的更多相关文章
- 1653: Champion of the Swordsmanship
1653: Champion of the Swordsmanship Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 11 Solved: 8[Subm ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- AC日记——蓬莱山辉夜 codevs 2830
2830 蓬莱山辉夜 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 在幻想乡中,蓬莱山辉夜是月球 ...
- codevs 2830 蓬莱山辉夜
2830 蓬莱山辉夜 http://codevs.cn/problem/2830/ 题目描述 Description 在幻想乡中,蓬莱山辉夜是月球公主,居住在永远亭上,二次设定说她成天宅在家里玩电脑, ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
随机推荐
- 《高性能MySQL》读书笔记之创建高性能的索引
索引是存储引擎用于快速找到记录的一种数据结构.索引优化是对查询性能优化的最有效手段.索引能够轻易将查询性能提高几个数量级.创建一个最优的索引经常需要重写查询.5.1 索引基础 在MySQL中,存储引擎 ...
- [BZOJ1047][HAOI2007]理想的正方形 二维单调队列
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1047 我们对每矩阵的一列维护一个大小为$n$的单调队列,队中元素为矩阵中元素.然后扫描每一 ...
- greendao 查询之数据去重
最近使用greendao的过程中,有一个需求:将数据库的内容根据组别展示.意思就是需要将数据库中的所有组别取出来,然后根据组别加载数据.之前我的笨办法是获取所有的数据,然后对得到的数据手动去重(比较每 ...
- Yii2中多表关联查询(with、join、joinwith)
表结构 现在有客户表.订单表.图书表.作者表, 客户表Customer (id customer_name) 订单表Order (id order_name custome ...
- Xmind几个有用的技巧
Xmind是一个很好的思维导图工具,是学习研究总结的好帮手. Xmind功能很丰富,这里只是简要列出几个比较有用的技巧. 1.善用属性 选中一个xmind元素(专业名词叫[主题])后,一般在右下角会出 ...
- 再用python写一个文本处理的东东
朋友遇到一点麻烦,我自告奋勇帮忙.事情是这样的: - 他们的业务系统中,数据来自一个邮箱: - 每一个邮件包含一条记录: - 这些记录是纯文本的,字段之间由一些特殊字符分隔: - 他们需要从邮箱中批量 ...
- php 正则符号说明
preg_match_all ("/<b>(.*)<\/b>/U", $userinfo, $pat_array); preg_match_all (&qu ...
- codevs 1992 聚会
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 小S 想要从某地出发去同学k的家中参加一个party,但要有去有回.他想让所用的 ...
- 如何处理Docker错误消息:please add——insecure-registry
本地安装Kubernetes时,遇到如下的错误消息: pleade add --insecure-registry gcr.io to daemon's arguments 解决方案:点击Docker ...
- JavaScript的语音识别
有没有想过给您的网站增添语音识别的功能?比如您的用户不用点鼠标,仅仅通过电脑或者手机的麦克风发布命令,比如"下拉到页面底部",或者"跳转到下一页",您的网站就会 ...