版权声明:来自: 码代码的猿猿的AC之路 http://blog.csdn.net/ck_boss https://blog.csdn.net/u012797220/article/details/35860567

JAVA大数....

Children’s Queue

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10390    Accepted Submission(s): 3333

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

1
2
3
 

Sample Output

1
2
4
 

Author
SmallBeer (CML)
 

Source
 
import java.util.*;
import java.math.*; public class Main
{
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in); BigInteger[] a=new BigInteger[1100];
a[1]=BigInteger.valueOf(1);
a[2]=BigInteger.valueOf(2);
a[3]=BigInteger.valueOf(4);
a[4]=BigInteger.valueOf(7);
for(int i=5;i<=1000;i++)
{
a[i]=a[i-4].add(a[i-2].add(a[i-1]));
} while(cin.hasNextInt())
{
int n=cin.nextInt();
System.out.println(a[n]);
}
}
}

HDOJ 1297 Children’s Queue的更多相关文章

  1. HDU 1297 Children’s Queue (递推、大数相加)

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. HDOJ/HDU 1297 Children’s Queue(推导~大数)

    Problem Description There are many students in PHT School. One day, the headmaster whose name is Pig ...

  3. 【HDOJ】1297 Children’s Queue

    递推,最近发现自己做递推的题总是没有思路.下周多练习.对于f(n)可以在第n个位置为男生,此时共有f(n-1)种情况:若在第n个位置为女生,因此第n-1个位置也必须为女生.此时有两种情况,一种情况是在 ...

  4. 杭电ACM 1297 Children’s Queue

    这道题是排序问题,可以用递归方法解决. 计算F(n): 一:当最后一个是男孩M时候,前面n-1个随便排出来,只要符合规则就可以,即是F(n-1): 二:当最后一个是女孩F时候,第n-1个肯定是女孩F, ...

  5. Children’s Queue(hdu1297+递推)

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. HDU1297 Children’s Queue (高精度+递推)

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. 【高精度递推】【HDU1297】Children’s Queue

    Children's Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. Children’s Queue

    Children's Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. (递推 大整数) Children’s Queue hdu1297

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. 关于Java课堂实验中的一些总结(Scanner)

    import java.util.Scanner; 这个头文件是java里面用来输入东西的,就相当于c++里面的iostream输入流...?暂且这么理解吧 然后使用方法:Scanner in = n ...

  2. Java伪代码之大道至简读后感

    import.java.大道至简.*; import.java. 愚公移山.*; public class YuGongYiShan//定义一个名为YuGongYiShan的类 {//类定义的开始 S ...

  3. Java语法基础学习DayTwo

    一.数据类型补充问题 数据类型的自动转换等级: byte,short,char -- int -- long -- float -- double long是8个字节,float是4个字节,为什么是这 ...

  4. vue中使用sass 做减法计算

    首先确认已安装sass依赖, yarn指令:yarn add sass-loader, style中写法如下: 注意calc(100% - 200px); 之间有两个空格的,

  5. 九、编写led驱动

    led.c #include <linux/init.h> #include <linux/module.h> #include <linux/cdev.h> #i ...

  6. arduino使用oled显示时间MQ_2温湿度

    这代码一般都是复制过来,在小改下就行了 代码如下: double Fahrenheit(double celsius) { ; } //摄氏温度度转化为华氏温度 double Kelvin(doubl ...

  7. ios中字典转模型的创建以及简单用法

    // appModel.h // Created by zzqqrr on 17/8/19. // #import <Foundation/Foundation.h> @interface ...

  8. redis 基础应用

          redis 安装  -redis安装 -window的安装 -redis支持5大数据类型 -字符  Memcached 只支持字符串类型 -列表 -字典 -集合 -有序集合  面试题:游戏 ...

  9. java学习笔记18(基本类型包装类,system类)

    基本类型包装类 定义:程序界面用户输入的数据都是以字符串类型存储的,如果需要操作这些字符串进行运算,需要转成基本数据类型,这时就要用到基本类型包装类,例: public class Demo { pu ...

  10. 【转载】 火爆的996.ICU项目正在酝酿开源许可证 禁止996公司使用

    原文地址: https://www.cnbeta.com/articles/tech/832449.htm ---------------------------------------------- ...