Children’s Queue大数加法及规律
来源:互联网 发布:查找淘宝用户购买记录 编辑:程序博客网 时间:2024/05/19 14:52
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?
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
Author
SmallBeer (CML)
Source
杭电ACM集训队训练赛(VIII)
Recommend
lcy
先写出前面几个来,可以发现规律f[i]=f[i-1]+f[i-2]+f[i-4];注意当1000的时候会爆long long所以要用大数!!!
代码:
#include<stdio.h>#include<string.h>char a[1005][1001];void add(int x,int y){//计算两个数相加,将各个位置的数转化为int型进行计算,然后判断是否大于10,大于10则将z=1,否则赋为0. int len_a,len_b; len_a=strlen(a[x]); len_b=strlen(a[y]); int z=0; int tx,ty,t,i=0; while(i<len_a||z==1){//如果最后z=1则继续循环将1加到末尾 tx=ty=t=0; if(i<len_a) tx=a[x][i]-'0';//如果i>=len_a则tx为之前赋的0值,对计算无影响了。 if(i<len_b) ty=a[y][i]-'0';//同上。 t=tx+ty+z;//计算两个数同一位数的值,如果上两个数的值大于10则加上z的值否则为0,对计算无影响 if(t>=10){//判断此时的值是否大于10,如果大于10则t-10&&z=1 t=t-10; z=1; } else//如果此时t不大于10则赋0。 z=0; a[x][i]=t+'0'; i++; }}int main(){ int n,i; a[1][0]='1'; a[2][0]='2'; a[3][0]='4'; a[4][0]='7'; for(i=5;i<=1000;i++){ strcpy(a[i],a[i-1]); add(i,i-2);//计算a[i-1]+a[i-2]. add(i,i-4);//计算a[i-1]+a[i-2]+a[i-4]. } while(scanf("%d",&n)!=EOF){ for(i=strlen(a[n])-1;i>=0;i--)//注意将位置颠倒过来,i=0时是各位,输出时应是最高位。 printf("%c",a[n][i]); printf("\n"); } return 0;}
阅读全文
0 0
- Children’s Queue大数加法及规律
- hdu 1297 Children’s Queue (大数加法+递推)
- hdu 1297 children's queue #DP#大数
- HDU 大数模板之Children’s Queue
- Children’s Queue 1297 (大数)
- HDU 1297 Children’s Queue 递归+大数
- Children’s Queue (大数/高精度)
- hdu 1297 Children’s Queue(找规律+高精度)
- hdu 1297 Children’s Queue(递推+大数)
- 【大数递推】HDU 1297——Children’s Queue
- yt13递推Children’s Queue (大数)
- hdu 1297 Children’s Queue(大数处理)
- HDOJ 题目1297Children’s Queue(递推,大数)
- HDU 1297 Children’s Queue(含整型大数模板)
- 杭电acm 1297 Children's Queue.大数加递归
- hdoj.1297 Children’s Queue【大数+排列组合】 2015/08/06
- HDOJ/HDU 1297 Children’s Queue(推导~大数)
- ACM--学生排队--HDOJ 1297--Children’s Queue--大数
- 将独立 的mongod数据库转换成副本模式,可以只需要一台机器一个实例
- python实时得到鼠标的位置
- 基于Unity3D(UGUI)的背包系统<四>完结篇
- eclipse中远程调试JVM(以启动namenode进程为例)
- 蓝牙之六-A2dp代码调用流程
- Children’s Queue大数加法及规律
- 用vlc搭建简单流媒体服务器(UDP和TCP方式)
- 安卓记事本实验报告
- 简述js中 for in 与 for of 区别
- Android 进阶15:HandlerThread 使用场景及源码解析
- sed & awk & grep
- R语言分图散点图
- 欢迎使用CSDN-markdown编辑器
- 现代软件工程-构建之法(第四,五章)