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/ ...
随机推荐
- 在Salesforce中可以对某一个Object的Standard Button或Link进行重写
在Salesforce中可以对某一个Object的Standard Button或Link进行重写,来实现我们特定的逻辑过程,比如:在删除某个Object之前要判断该Object的某个Field的状态 ...
- 【bootstrapValidator 不验证】使用bootstrapValidator 验证效果不起作用
虽然在页面ready的时候 就绑定了验证表单 ,但是在点击提交按钮之后 依旧没有验证的效果 . 那就在提交按钮的点击事件中 添加一句话: $(document).ready( function () ...
- RDLC的部署(无法找到Microsoft.ReportViewer.ProcessingObjectModel.dll文件)
CMD命令:C:\Windows\assembly\GAC_MSIL\ rdlc 相比微软的其他产品来说,做得还真是够烂的了,比水晶报表也烂得多. 但不知为何我还是宁可先择 rdlc.并且渐渐上手了. ...
- HTTP基础08--追加协议
消除 HTTP 瓶颈的 SPDY HTTP 的瓶颈 Web 网站为了保存这些新增内容,在很短的时间内就会发生大量的内容更新;为了尽可能实时地显示这些更新的内容,服务器上一有内容更新,就需要直接把那些内 ...
- js三级省市区选择
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- 静态函数(面向过程的static关键字)
在函数的返回类型前加上static关键字,函数即被定义为静态函数.静态函数与普通函数不同,它只能在声明它的文件中可见,不能被其他文件使用. 静态函数的例子: #include <iostream ...
- Android自动化测试 - 自动化测试工具比较
- 我认为我可以去尝试做一下Maya Ue4导出插件
Begin Map Begin Level Begin Actor class="StaticMeshActor" Name=Floor Archetype=StaticMeshA ...
- NUC_HomeWork1 -- POJ2067(最短路)
C - Fire Station Description A city is served by a number of fire stations. Some residents have comp ...
- jquery ajax 提交信息后等待返回的提示信息
最简单的方法: http://bbs.csdn.net/topics/390584283?page=1 $('#click').click(function){ $('#data').html('&l ...