题意:给你一个长度为 n 的木棒,求至少拿掉几根使得剩余的木棒构成不了三角形。

析:为了保证不形成三角形,所以保证两边之和等于最大边是最优,这不就是Fibnacci 数么,由于 n 很小,if-else 就好。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. //#include <tr1/unordered_map>
  17. #define freopenr freopen("in.txt", "r", stdin)
  18. #define freopenw freopen("out.txt", "w", stdout)
  19. using namespace std;
  20. //using namespace std :: tr1;
  21.  
  22. typedef long long LL;
  23. typedef pair<int, int> P;
  24. const int INF = 0x3f3f3f3f;
  25. const double inf = 0x3f3f3f3f3f3f;
  26. const LL LNF = 0x3f3f3f3f3f3f;
  27. const double PI = acos(-1.0);
  28. const double eps = 1e-8;
  29. const int maxn = 1e3 + 5;
  30. const LL mod = 10000000000007;
  31. const int N = 1e6 + 5;
  32. const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
  33. const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
  34. const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  35. inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
  36. int n, m;
  37. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  38. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  39. inline int Min(int a, int b){ return a < b ? a : b; }
  40. inline int Max(int a, int b){ return a > b ? a : b; }
  41. inline LL Min(LL a, LL b){ return a < b ? a : b; }
  42. inline LL Max(LL a, LL b){ return a > b ? a : b; }
  43. inline bool is_in(int r, int c){
  44. return r >= 0 && r < n && c >= 0 && c < m;
  45. }
  46.  
  47. int main(){
  48. int T; cin >> T;
  49. for(int kase = 1; kase <= T; ++kase){
  50. cin >> n;
  51. printf("Case #%d: ", kase);
  52. if(n < 4) printf("0");
  53. else if(n < 6) printf("1");
  54. else if(n < 8) printf("%d", n-4);
  55. else if(n < 13) printf("%d", n-5);
  56. else printf("%d", n-6);
  57. printf("\n");
  58. }
  59. return 0;
  60. }

HDU 2914 Triangle (Fibnacci 数)的更多相关文章

  1. [Usaco2010 OPen]Triangle Counting 数三角形

    [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 394  Solved: 1 ...

  2. bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形 容斥

    1914: [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 272  Sol ...

  3. 网络流(最大流) HDU 1565 方格取数(1) HDU 1569 方格取数(2)

      HDU 1565 方格取数(1) 给你一个n*n的格子的棋盘,每个格子里面有一个非负数.从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的 ...

  4. HDU 1565 - 方格取数(1) - [状压DP][网络流 - 最大点权独立集和最小点权覆盖集]

    题目链接:https://cn.vjudge.net/problem/HDU-1565 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32 ...

  5. bzoj1914 [Usaco2010 OPen]Triangle Counting 数三角形 计算机和

    [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 526  Solved: 2 ...

  6. HDU 5914 Triangle(打表——斐波那契数的应用)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Problem Description Mr. Frog has n sticks, whos ...

  7. HDU 1394Minimum Inversion Number 数状数组 逆序对数量和

    Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  8. HDU 5914 Triangle 数学找规律

    Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, who ...

  9. hdu 4324 Triangle LOVE

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4324 Triangle LOVE Description Recently, scientists f ...

随机推荐

  1. jvm的类加载器,类装载过程

    混沌初开,在一片名为jvm的世界中,到处都是一片虚无,直到一个名为BootstrapClassLoader的巨人劈开了世界,据说它是由名叫C++的女神所造,它从一个叫做jre/lib的宝袋中拿出一把开 ...

  2. 搭建nexus私服,无法下载相关jar包,报错Repository proxy-mode is BLOCKED_AUTO

    在搭建nexus私服的时候,之前没直接用来下载maven的相关插件jar包,一直可以使用, 结果今天要编译hadoop的时候,在linux上新用maven就报错了,无法下载maven的相关插件(如下) ...

  3. mysql获取行号的方法

    1.不排序 语句: ) ) ) b,bigquestion 结果:  2.排序的 语句 ) ) ) b,bigquestion order by bigquestion.bigQuestionSequ ...

  4. 51nod 马拉松30 C(构二分图+状压dp)

    题意 分析 考虑一个图能被若干简单环覆盖,那么一定是每个点恰好一个出度,恰好一个出度 于是类似最小路径覆盖的处理,我们可以把每个点拆成2个点i和i',如果有一条边(i,j),那么将i和j'连起来 那么 ...

  5. Java实验--课上提到的随机数生成原理简单实现(不利用库生成随机数的简单算法)

    对于随机数的实验,根据课程上的教程,有如下的公式: 对应的变量参数的说明: 其中对应的Mouduls变量对应的就是公式中a的值,在公式中的含义就是相当于要循环多少个数才重复的一个值. Multipli ...

  6. mysql资料整理

    ###SQL的语言分类 1.DQL(Data Query Language):数据查询语言 select 2.DML(Data Manipulate Language):数据操作语言 insert . ...

  7. Python pandas学习笔记

    参考文献:<Python金融大数据分析> #导入模块 import pandas as pd #生成dataframe df = pd.DataFrame([10,20,30,40], c ...

  8. 表皮囊肿?wtf

    https://baike.baidu.com/item/%E8%A1%A8%E7%9A%AE%E5%9B%8A%E8%82%BF/7852024?fr=aladdin

  9. python解析xml文件之xml.etree.cElementTree和xml.etree.ElementTree区别和基本使用

    1.解析速度:ElementTree在 Python 标准库中有两种实现.一种是纯 Python 实现例如 xml.etree.ElementTree ,另外一种是速度快一点的 xml.etree.c ...

  10. zedboard硬件连接过程

    1.      ZedBoard – Connect a 2nd micro-USBcable between the host machine and connector J17 (JTAG) 2. ...