题意:给你一个长度为 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. 移动web页面字体大小二

    按设计稿中的字体大小设置页面字体大小(px),在手机端,因为不同设备会有不同,换算成rem单位.rem是“font size of the root element”,可以通过这篇文章了解http:/ ...

  2. django学习之- 信号

    - Django内置的信号Model signals pre_init # django的modal执行其构造方法前,自动触发 post_init # django的modal执行其构造方法后,自动触 ...

  3. .NET Core 3.0之深入源码理解Configuration(一)

    Configuration总体介绍 微软在.NET Core里设计出了全新的配置体系,并以非常灵活.可扩展的方式实现.从其源码来看,其运行机制大致是,根据其Source,创建一个Builder实例,并 ...

  4. Linux--进程组、会话、守护进程(转)

    http://www.cnblogs.com/forstudy/archive/2012/04/03/2427683.html 进程组 一个或多个进程的集合 进程组ID: 正整数 两个函数 getpg ...

  5. Linux下使用Curl调用Java的WebService接口

    其实只要是标准的WSDL的SOA接口WebService都可以用. 调用方式: 注意:上面的方式不包括加密或者登录的,其实SOA有一套完整的加密方式. curl -H'Content-Type: te ...

  6. Github配置SSH

    以前也配置过ssh,但是没有注意用法,在配置一次熟悉流程 检查本机是否有ssh key设置 $ cd ~/.ssh 或cd .ssh 如果没有则提示: No such file or director ...

  7. CentOS7 设置系统时间

    在CentOS 6版本,时间设置有date.hwclock命令, 硬件时钟和系统时钟 (1) 硬件时钟 RTC(Real-Time Clock)或CMOS时钟,一般在主板上靠电池供电,服务器断电后也会 ...

  8. Javascript setTimeout(0),闭包

    setTimeout常常被用于延迟运行某个函数,使用方法为 setTimeout(function(){ - }, timeout); 有时为了进行异步处理,而使用setTimeout(functio ...

  9. [React] Use the Fragment Short Syntax in Create React App 2.0

    create-react-app version 2.0 added a lot of new features. One of the new features is upgrading to Ba ...

  10. Atitit. 软件GUIbutton与仪表盘--webserver区--获取apache配置文件路径 linux and apache的启动、停止、重新启动

    Atitit.   软件GUIbutton与仪表盘--webserver区--获取apache配置文件路径 linux and apache的启动.停止.重新启动 能够通过"netstat  ...