HDU 5914 Triangle【找规律】【2016中国大学生程序设计竞赛(长春)】
来源:互联网 发布:ci框架数据库配置 编辑:程序博客网 时间:2024/06/05 16:36
Triangle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 578 Accepted Submission(s): 382
Problem Description
Mr. Frog has n sticks, whose lengths are 1,2, 3⋯ n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides to steal some sticks! Output the minimal number of sticks he should steal so that Mr. Frog cannot form a triangle with
any three of the remaining sticks.
any three of the remaining sticks.
Input
The first line contains only one integer T (T≤20 ), which indicates the number of test cases.
For each test case, there is only one line describing the given integer n (1≤n≤20 ).
For each test case, there is only one line describing the given integer n (
Output
For each test case, output one line “Case #x: y”, where x is the case number (starting from 1), y is the minimal number of sticks Wallice should steal.
Sample Input
3456
Sample Output
Case #1: 1Case #2: 1Case #3: 2
Source
2016中国大学生程序设计竞赛(长春)-重现赛
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5914
题意:有n根长度为1-n的木棍,问你最少拿去多少根,使得剩下的不能构成三角形。
经过推测,使得剩下的木棍长度构成Fibobacci数列,就不能构成三角形。
有人直接写答案,但是20个数有点烦,能用循环解决的就不用‘暴力’。
AC代码:
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int maxn=25;bool vis[maxn];int ans[maxn];int main(){ int x=0,y=1; vis[1]=true; while(true) { vis[x]=true; y+=x; x=y-x; if(y>maxn) break; } int cnt=0; for(int i=0; i<maxn; i++) { if(!vis[i]) cnt++; ans[i]=cnt; } int T,kase=0; cin>>T; int n; while(T--) { cin>>n; printf("Case #%d: %d\n",++kase,ans[n]); } return 0;}
尊重原创,转载请注明出处:http://blog.csdn.net/hurmishine
0 0
- HDU 5914 Triangle【找规律】【2016中国大学生程序设计竞赛(长春)】
- HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))
- HDU Triangle 2016中国大学生程序设计竞赛(长春)-重现赛
- hdu 5914 Triangle 2016中国大学生程序设计竞赛(长春)(脑洞题)
- HDU 5914 Triangle【斐波那契思维】(2016中国大学生程序设计竞赛(长春)D题)
- HDU Fraction 2016中国大学生程序设计竞赛(长春)-重现赛
- hdu 5912 Fraction 2016中国大学生程序设计竞赛(长春) 水题
- hdu 5912 Fraction -2016中国大学生程序设计竞赛(长春)
- 【HDU 5914 Sequence I】+ 2016中国大学生程序设计竞赛(长春)-重现赛
- HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))
- HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
- HDU 5918 Sequence I【暴力+剪枝】(2016中国大学生程序设计竞赛(长春)H题)
- HDU Harmonic Value Description 2016中国大学生程序设计竞赛(长春)-重现赛
- HDU Sequence I 2016中国大学生程序设计竞赛(长春)-重现赛
- HDU Ugly Problem 2016中国大学生程序设计竞赛(长春)-重现赛
- HDU 5912 【模拟,类连分数的计算】【2016中国大学生程序设计竞赛(长春)】
- HDU 5916 Harmonic Value Description【构造】【2016中国大学生程序设计竞赛(长春)】
- HDU 5918 Sequence I【KMP?】【2016中国大学生程序设计竞赛(长春)】
- poj1716 Integer Intervals(差分约束)
- 文件锁之flock()函数
- 防止数据重复提交
- 【批处理】35.备份Mysql中所有数据库——mysqldump命令
- codevs 1045 回文数 题解报告
- HDU 5914 Triangle【找规律】【2016中国大学生程序设计竞赛(长春)】
- Git常用操作
- 一个简单的可以接收TCP服务器数据的TCP客户端
- TCP/IP详解学习笔记(2)-数据链路层
- [prime模板]
- java中的运算符!!绝对经典!值得收藏!!
- 20161021 观《吴清源》
- ESP8266 无法连接手机
- 排序链表中去重