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 = ...
随机推荐
- AJPFX关于单例设计模式
单例设计模式优势:保证一个类在内存中的对象唯一性. 比如:多程序读取一个配置文件时,建议配置文件封装成对象.会方便操作其中数据,又要保证多个程序读到的是同一个配置文件对象,就需要该配置文件对象在内存中 ...
- css3 变换、过渡效果、动画
1 CSS3 选择器 1.1 基本选择器 1.2 层级 空格 > + .item+li ~ .item~p 1.3 属性选择器 [attr] [attr=value] [attr^=value] ...
- Android Studio中通过CMake使用NDK并编译自定义库和添加预编译库
Note:这篇文章是基于Android Studio 3.01版本的,NDK是R16. step1:创建一个包含C++的项目 其他默认就可以了. C++ Standard 指定编译库的环境,其中Too ...
- uvm_monitor——借我一双慧眼
monitor 用来捕获(监视)和检查总线的信号是否满足预期的要求.所有的user_monitor 继承自uvm_monitor,uvm_monitor继承自uvm_component,从源代码来看里 ...
- vue+element ui项目总结点(五)Carousel 走马灯组件、Collapse 折叠面板、Tree 树形控件
<template> <div class="ele_test_box"> <!-- 常用效果 Popover 弹出框组件 具体属性查看官方文档--& ...
- Android学习总结(九)———— 内容提供器(ContentProvider)
一.内容提供器基本概念 内容提供器主要用于在不同的应用程序之间实现数据共享的功能,它提供了一套完整的机制,允许一个程序访问另一个程序中的数据,同时还能保证被访数据的安全性.详细资料请看下图: 二.示例 ...
- SQLite基础教程目录
SQLite基础教程目录 SQLite主页 SQLite概述 SQLite -安装 SQLite -命令 SQLite -语法 SQLite -数据类型 SQLite -创建数据库 SQLite -附 ...
- C++类构造函数、析构函数运行机理
http://blog.sina.com.cn/s/blog_6fd68d5f0100n60h.html 前言--构造函数.析构函数的简单理解:1)构造函数---对象被创建时候调用的函数:2)析构函数 ...
- NTFS文件系统结构及文件恢复
结构部分参考了 https://www.cnblogs.com/mwwf-blogs/archive/2015/05/04/4467687.html 以及P老师的课件. 文件恢复参考: https: ...
- HTML之网页的基本介绍
一.web的基本介绍 web就是world wide web的缩写,称之为全球广域网,俗称WWW 可以将web理解成一种当前的互联网,对于我们来说更多的就是网站服务 网站我们可以理解成是由很多网页组合 ...