Children’s Queue

来源:互联网 发布:java函数命名规范 编辑:程序博客网 时间:2024/06/01 10:23

Children’s Queue

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1271 Accepted Submission(s): 662 
Problem Description
There are many students in PHT School. One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single. In other words, either no girl in the queue or more than one girl stands side by side. The case n=4 (n is the number of children) is like
FFFF, FFFM, MFFF, FFMM, MFFM, MMFF, MMMM
Here F stands for a girl and M stands for a boy. The total number of queue satisfied the headmaster’s needs is 7. Can you make a program to find the total number of queue with n children?
 
Input
There are multiple cases in this problem and ended by the EOF. In each case, there is only one integer n means the number of children (1<=n<=1000)
 
Output
For each test case, there is only one integer means the number of queue satisfied the headmaster’s needs.
 
Sample Input
123
 
Sample Output
124
#include<stdio.h>//又是大数加法类的#include<string.h>using namespace std;char p[1005][1001];void add(int x,int y){ int a,b; a=strlen(p[x]); b=strlen(p[y]); int z=0; int tx,ty,t,i=0; while(i<a||z==1){  tx=ty=t=0;  if(i<a)   tx=p[x][i]-'0';  if(i<b)   ty=p[y][i]-'0';  t=tx+ty+z;  if(t>=10){   t=t-10;   z=1;  }  else   z=0;  p[x][i]=t+'0';  i++; }}int main(){ int n,i; p[1][0]='1'; p[2][0]='2'; p[3][0]='4'; p[4][0]='7'; for(i=5;i<=1000;i++){strcpy(p[i],p[i-1]);  add(i,i-2);  add(i,i-4); } while(scanf("%d",&n)!=EOF){  for(i=strlen(p[n])-1;i>=0;i--)   printf("%c",p[n][i]);  printf("\n"); } return 0;}