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.
For each test case, there is only one line describing the given integer n (1≤n≤201≤n≤20).
3 4 5 6
Case #1: 1 Case #2: 1Case #3: 2
我是用队列模拟写的。
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; int main() { queue<int>que; int a[100]; a[0]=a[1]=a[2]=a[3]=0; que.push(3); que.push(2); int n,m,k; int ans=0; k=4; while(k<=20) { n=que.front(); que.pop(); m=que.front(); if(n+m>k) { ans++; que.push(n); a[k]=ans; } else { que.push(k); a[k]=ans; } k++; } int p=1; scanf("%d",&n); while(n--) { scanf("%d",&m); printf("Case #%d: ",p); printf("%d\n",a[m]); p++; } return 0; }