首页 > 代码库 > HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))
HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))
Triangle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0Problem DescriptionMr. 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.
InputThe 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).
OutputFor 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 Input3456
Sample OutputCase #1: 1Case #2: 1Case #3: 2
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5914
题目大意:
给你1~N(N<=20)长度的木棒,求至少拿掉几根使得剩余的木棒构成不了三角形。
题目思路:
【模拟】
画画前几个就可以得出,剩下的木棒是斐波那契数列1,2,3,5,8,13。N只有20,打表。
1 // 2 //by coolxxx 3 //#include<bits/stdc++.h> 4 #include<iostream> 5 #include<algorithm> 6 #include<string> 7 #include<iomanip> 8 #include<map> 9 #include<stack>10 #include<queue>11 #include<set>12 #include<bitset>13 #include<memory.h>14 #include<time.h>15 #include<stdio.h>16 #include<stdlib.h>17 #include<string.h>18 //#include<stdbool.h>19 #include<math.h>20 #define min(a,b) ((a)<(b)?(a):(b))21 #define max(a,b) ((a)>(b)?(a):(b))22 #define abs(a) ((a)>0?(a):(-(a)))23 #define lowbit(a) (a&(-a))24 #define sqr(a) ((a)*(a))25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))26 #define mem(a,b) memset(a,b,sizeof(a))27 #define eps (1e-10)28 #define J 1000029 #define mod 100000000730 #define MAX 0x7f7f7f7f31 #define PI 3.1415926535897932332 #pragma comment(linker,"/STACK:1024000000,1024000000")33 #define N 10434 using namespace std;35 typedef long long LL;36 double anss;37 LL aans,sum;38 int cas,cass;39 int n,m,lll,ans;40 int a[]={0,0,0,0,1,1,2,3,3,4,5,6,7,7,8,9,10,11,12,13,14};41 int main()42 {43 #ifndef ONLINE_JUDGEW44 // freopen("1.txt","r",stdin);45 // freopen("2.txt","w",stdout);46 #endif47 int i,j,k;48 // init();49 // for(scanf("%d",&cass);cass;cass--)50 for(scanf("%d",&cas),cass=1;cass<=cas;cass++)51 // while(~scanf("%s",s))52 // while(~scanf("%d",&n))53 {54 scanf("%d",&n);55 printf("Case #%d: ",cass);56 printf("%d\n",a[n]);57 }58 return 0;59 }60 /*61 //62 63 //64 */
HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。