Topic link: http: //hihocoder.com/contest/icpcbeijing2018/problem/4
Meaning of the questions: frog can jump from p p + 1, p + 2, now the frog jumps from 0 200, you can install the portal ai-aj a frog will jump to ai aj, may form a loop, each Portals ai different,
After seeking security portal, frogs jump program number is exactly 200 m of placement method
answer:
I did not do it. . We see the solution to a problem, I feel an ingenious
flat:
Any positive integer that can be broken down into a number of different Fibonacci number Pact and
f [48] << 1 has greater than 32, and can be subtracted from the Fibonacci descending, even upside down when scored, such as from 199-200 = 1,198-200 = 2,197-200 = 3 ......, and even 1 197,3 198,5 even 197 connected end to end their own node even 6-6
A front spacer connected to a rear, such as front of each embodiment 1, is not connected to the back of the impact on the back.
Even as the first 1-195, 3-198 and even a, that is equivalent to a 1 in 198 plus program, 199 program also added 1, 200 plus 2 program, but also a fresh start Fibonacci superimposed He scored on a front.
Figure
planb: If we at x, programs for m, m is an even number: Connection x + 1 ~ x + 3, x + 2 ~ x + 3, x + 3 to this embodiment there are two kinds, the problem becomes to x + 3 200, programs for m / 2,
m is an odd number, even x + 1 ~ 200, becomes a problem to x + 2 m 1-200 Proposed program number of the program
Sentenced to 0,1 special circumstances
AC Code:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int const maxn=210; 4 typedef long long ll; 5 long long f[maxn],m,tot,ans[maxn]; 6 void getfi(){ 7 f[200]=1;f[199]=1; 8 for(int i=198;i>=150;i--)f[i]=f[i+1]+f[i+2]; 9 } 10 void work(){ 11 if(m==0){ 12 printf("2\n1 1\n2 1\n");return ; 13 } 14 if(m==1){ 15 printf("2\n1 199\n2 2\n");return ; 16 } 17 if(m==2){printf("2\n1 2\n2 199\n");return ;} 18 for(ll i=150;i<=199;i++){ 19 if(m==0)break; 20 if(m-f[i]>=0){ 21 ans[++tot]=i; 22 m-=f[i]; 23 } 24 } 25 printf("%lld\n",tot+1); 26 for(int i=1;i<=tot;i++)printf("%d %lld\n",i*2-1,ans[i]); 27 printf("%lld %lld\n",tot*2,tot*2); 28 } 29 int main(){ 30 getfi(); 31 while(scanf("%lld",&m)!=EOF){ 32 tot=0; 33 work(); 34 } 35 return 0; 36 }