版权声明:来自: 码代码的猿猿的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. python+appium+yaml安卓UI自动化测试分享

    一.实现数据与代码分离,维护成本较低,先看看自动化结构,大体如下: testyaml管理用例,实现数据与代码分离,一个模块一个文件夹 public 存放公共文件,如读取配置文件.启动appium服务. ...

  2. nginx随机模块——ngx_http_random_index_module

    今天我给大家分享一个挺好玩的模块,随机变换网站首页的模块 这个模块他的作用于只有在location中,具体写法如下 只需要在localtion开启这个模块就好了,然后呢我们在/usr/share/ng ...

  3. 用MFC库函数AfxBeginThread()来创建线程

    在进行多线程程序设计的时候,我们经常用到AfxBeginThread函数来启动一条线程该函数使用起来非常的简单方便,其定义如下: 1.函数原型 CWinThread* AfxBeginThread( ...

  4. 解决 java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()L的问题

    <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</a ...

  5. centos安装python3虚拟环境和python3安装

    1.本文的系统命令一般会在语句前加上#号,以区分系统命令及其他内容.输入命令时,无需输入#号. # yum install vim 2.本文系统输出的信息,会在前面加上>>号. # whi ...

  6. [BUG]数据库日期格式, 到页面是毫秒值

    springboot 配置文件

  7. python3:logging模块 输出日志到文件

    python自动化测试脚本运行后,想要将日志保存到某个特定文件,使用python的logging模块实现 参考代码: import logging def initLogging(logFilenam ...

  8. 【MySQL】5.6.x InnoDB Error Table mysql.innodb_table_stats not found

    [问题描述]: 检查error log的时候发现大量warnings: [Warning] InnoDB Error Table mysql.innodb_index_stats not found ...

  9. 【Python】xpath-1

    1.coverage包实现代码覆盖率 (1)pip install coverage (2)coverage run XX.py(测试脚本文件) (3)coverage report -m 在控制台打 ...

  10. ES6 声明变量的6种方法

    ES5 只有两种声明变量的方法:var命令和function命令. ES6除了添加let和const命令,后面章节还会提到,另外两种声明变量的方法:import命令和class命令.所以,ES6 一共 ...