HDU 5914 Triangle 构造 (2016中国大学生程序设计竞赛(长春))

Posted Coolxxx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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): 0


Problem Description
Mr. Frog has n sticks, whose lengths are 1,2, 3n 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.
 

 

Input
The first line contains only one integer T (T20), which indicates the number of test cases. 

For each test case, there is only one line describing the given integer n (1n20).
 

 

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
3 4 5 6
 

 

Sample Output
Case #1: 1 Case #2: 1 Case #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 10000
29 #define mod 1000000007
30 #define MAX 0x7f7f7f7f
31 #define PI 3.14159265358979323
32 #pragma comment(linker,"/STACK:1024000000,1024000000")
33 #define N 104
34 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_JUDGEW
44 //    freopen("1.txt","r",stdin);
45 //    freopen("2.txt","w",stdout);
46     #endif
47     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 */
View Code

 

以上是关于HDU 5914 Triangle 构造 (2016中国大学生程序设计竞赛(长春))的主要内容,如果未能解决你的问题,请参考以下文章

Triangle HDU - 5914

hdu 5914 Triangle

CCPC2016长春D (hdu 5914 Triangle)

QDU-Training-01

HDU5914

HDU 4466 Triangle