HDU1134/HDU1133 递推 大数 java
Game of Connections
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4246 Accepted Submission(s): 2467
is a small but ancient game. You are supposed to write down the numbers
1, 2, 3, ... , 2n - 1, 2n consecutively in clockwise order on the
ground to form a circle, and then, to draw some straight line segments
to connect them into number pairs. Every number must be connected to
exactly one another. And, no two segments are allowed to intersect.
It's
still a simple game, isn't it? But after you've written down the 2n
numbers, can you tell me in how many different ways can you connect the
numbers into pairs? Life is harder, right?
line of the input file will be a single positive number n, except the
last line, which is a number -1. You may assume that 1 <= n <=
100.
package luzhiyuan;
import java.util.Scanner;
import java.math.BigInteger;
public class java1 {
public static void main(String[] args){
BigInteger [][]a=new BigInteger[102][102];
BigInteger sta=BigInteger.valueOf(1); //把其他形式的数化为大整数
BigInteger zeo=BigInteger.valueOf(0);
for(int i=0;i<=100;i++)
for(int j=0;j<=100;j++)
a[i][j]=zeo; //如果想让后面的加法函数可用一定要给大整数赋初值
for(int i=1;i<=100;i++)
a[i][0]=sta;
for(int i=1;i<=100;i++)
for(int j=1;j<=i;j++){
a[i][j]=a[i][j].add(a[i-1][j]);
a[i][j]=a[i][j].add(a[i][j-1]);
}
Scanner cin=new Scanner(System.in);
while(cin.hasNext()){
int n=cin.nextInt();
if(n==-1) break;
System.out.println(a[n][n]);
}
}
}
Buy the Ticket
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6361 Accepted Submission(s): 2661
"Harry Potter and the Goblet of Fire" will be on show in the next few
days. As a crazy fan of Harry Potter, you will go to the cinema and have
the first sight, won’t you?
Suppose the cinema only has one
ticket-office and the price for per-ticket is 50 dollars. The queue for
buying the tickets is consisted of m + n persons (m persons each only
has the 50-dollar bill and n persons each only has the 100-dollar bill).
Now
the problem for you is to calculate the number of different ways of the
queue that the buying process won't be stopped from the first person
till the last person.
Note: initially the ticket-office has no money.
The
buying process will be stopped on the occasion that the ticket-office
has no 50-dollar bill but the first person of the queue only has the
100-dollar bill.
input file contains several test cases. Each test case is made up of
two integer numbers: m and n. It is terminated by m = n = 0. Otherwise,
m, n <=100.
each test case, first print the test number (counting from 1) in one
line, then output the number of different ways in another line.
package luzhiyuan;
import java.util.Scanner;
import java.math.BigInteger;
public class java1 {
public static void main(String[] args){
BigInteger [][]a=new BigInteger[102][102];
BigInteger sta=BigInteger.valueOf(1); //把其他形式的数化为大整数
BigInteger zeo=BigInteger.valueOf(0);
for(int i=0;i<=100;i++)
for(int j=0;j<=100;j++)
a[i][j]=zeo; //如果想让后面的加法函数可用一定要给大整数赋初值
for(int i=1;i<=100;i++)
a[i][0]=sta;
for(int i=1;i<=100;i++)
for(int j=1;j<=i;j++){
a[i][j]=a[i][j].add(a[i-1][j]);
a[i][j]=a[i][j].add(a[i][j-1]);
}
Scanner cin=new Scanner(System.in);
int t=0;
while(cin.hasNext()){
int n=cin.nextInt();
int m=cin.nextInt();
int nn=n,mm=m;
if(n==0&&m==0) break;
t++;
BigInteger x=BigInteger.valueOf(n);
BigInteger y=BigInteger.valueOf(m);
BigInteger ans=BigInteger.valueOf(1);
while(nn>1){
ans=ans.multiply(x);
nn--;
x=x.subtract(sta);
}
while(mm>1){
ans=ans.multiply(y);
mm--;
y=y.subtract(sta);
}
ans=ans.multiply(a[n][m]);
System.out.println("Test #"+t+":");
System.out.println(ans);
}
}
}
HDU1134/HDU1133 递推 大数 java的更多相关文章
- ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)
Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...
- Tiling(递推+大数)
Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tili ...
- Children’s Queue HDU 1297 递推+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...
- 【hdoj_1865】1sting(递推+大数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1865 本题的关键是找递推关系式,由题目,可知前几个序列的结果,序列长度为n=1,2,3,4,5的结果分别是 ...
- ACM学习历程—HDU1023 Train Problem II(递推 && 大数)
Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know ...
- Tiling 简单递推+大数
Tiling c[0]=1,c[1]=1,c[2]=3; c[n]=c[n-1]+c[n-2]*2; 0<=n<=250. 大数加法 java time :313ms 1 ...
- poj 2506 Tiling(递推 大数)
题目:http://poj.org/problem?id=2506 题解:f[n]=f[n-2]*2+f[n-1],主要是大数的相加; 以前做过了的 #include<stdio.h> # ...
- Buy the Ticket HDU 1133 递推+大数
题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元, m个人是只有50元一张的, n个人 ...
- hdu 1041(递推,大数)
Computer Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
随机推荐
- hibernate快速入门
第一步:下载Hibernate的开发包: http://sourceforge.net/projects/hibernate/files/hibernate3 第二步:Hibernate框架目录结构: ...
- Fragment详解之三——管理Fragment(1)
相关文章: 1.<Fragment详解之一--概述>2.<Fragment详解之二--基本使用方法>3.<Fragment详解之三--管理Fragment(1)>4 ...
- Liferay 6.2 改造系列之三:删除Docbar中的添加内容功能
在/portal-master/portal-web/docroot/html/portlet/dockbar/add_panel.jsp文件中 将以下内容: if (hasAddContentAnd ...
- ubuntu输入su命令显示 Authentication failure解决
由于ubuntu系统默认是没有激活root用户的,需要手动激活: 终端下输入: sudo passwd Password:你当前的密码 Enter new UNIX password:这个是root的 ...
- node.js整理 03文件操作-遍历目录和文本编码
遍历目录 递归算法 遍历目录时一般使用递归算法,否则就难以编写出简洁的代码. 递归算法与数学归纳法类似,通过不断缩小问题的规模来解决问题 function factorial(n) { if (n = ...
- ubuntu 下python版本切换
1. 安装ubuuntu 14.04之后python的默认版本为2.7.6但是我想使用python的版本为3.4 可以打开终端:输入:alias python = python3
- PDA手持移动POS销售开单软件(网络版)、PDA手持设备小票机
背景描述: 一家大中型批发及门店销售企业,经销多种冻食品,业务范围覆盖周边众多区域和城市.成立以来,随着业务量的扩大,产品销售分两大渠道:多门店销售和仓库批发,各门店每天都有大量的零散客户和老客户进行 ...
- WPF XAML之bing使用StringFormat
WPF XAML之bing使用StringFormat // 转化为百分比 Text="{Binding Progress, StringFormat=\{0:P\}}" < ...
- 【BZOJ1827】[Usaco2010 Mar]gather 奶牛大集会 树形DP
[BZOJ][Usaco2010 Mar]gather 奶牛大集会 Description Bessie正在计划一年一度的奶牛大集会,来自全国各地的奶牛将来参加这一次集会.当然,她会选择最方便的地点来 ...
- 一个动画 Label (走马观花)
UILabel中一个水平移动的Label UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 300, 300)]; U ...