HDU1134——Game of Connections (大数乘法,除法)+ (卡特兰数列)
2015-04-15 21:14
549 查看
Game of Connections
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 14 Accepted Submission(s) : 10
[align=left]Problem Description[/align]
This 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?
[align=left]Input[/align]
Each 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.
[align=left]Output[/align]
For each n, print in a single line the number of ways to connect the 2n numbers into pairs.
[align=left]Sample Input[/align]
2 3 -1
[align=left]Sample Output[/align]
2 5
[align=left]Source[/align]
Asia 2004, Shanghai (Mainland China), Preliminary
对于这道题,半天推导不出来,什么东西。唯有百度解决问题;发现了卡特兰数列,
竟然是大数模拟乘法,及除法。看了看书,又将大数乘法,除法搞定。。。
#include<stdio.h> #include<string.h> int map[110][110]; int main() { int i,j; int len=1; int temp=0; int r=0; int n; map[1][0]=1; //从第二项开始模拟乘法 for(i=2;i<=100;i++) { for(j=0;j<len;j++) { map[i][j]=map[i-1][j]*(4*i-2);//从低位依次相乘 } //对结果进行处理 r=0; for(j=0;j<len;j++) { temp=map[i][j]+r;//是否超过10; map[i][j]=temp%10; r=temp/10; } //遇见高位超出限制的话 for(;r;) { map[i][len]=r%10; r/=10; len++; } //同时进行模拟相除 //len--; r=0; for(j=len-1;j>=0;j--) { temp=map[i][j]+r*10;//去高位进行相除 map[i][j]=temp/(i+1); r=temp%(i+1); //有保留的话,下次调用 } //别忘记去掉高位的0 while(!map[i][len-1]) len--; } while(scanf("%d",&n)&&n!=-1) { int t=100; while(!map [t]) t--; for(;t>=0;t--) { printf("%d",map [t]); } printf("\n"); } return 0; }
相关文章推荐
- HDU 1134 卡特兰数 大数乘法除法
- HDU 1134 卡特兰数 大数乘法除法
- hdu-1134-Game of Connections(卡特兰数 大数乘法除法)
- HDU 1134 卡特兰数 大数乘法除法
- HDU 1023 大数与int小数 乘法 除法!!!!!!!!!!!!!
- HDU Buy the Ticket(大数除法乘法要注意)
- hdu 1130 How Many Trees?(卡特兰数,大数的乘法与除法)
- 组合数学 + 大数乘法 + 大数除法 之 hdu 1261 字串数
- HDU1134 Game of Connections(大数乘法+打表)
- HDU 1023 Train Problem II 卡特兰数 大数的乘法除法
- 【HDU】1130 - How Many Trees?(java - BigDecimal & 卡特兰大数打表)
- hdu 1023 1130 1134 卡特兰数 (中间有大数相除和大数相乘)
- HDU 1063 Exponentiation(大数乘法)
- 整数大数模拟 高精度加法 高精度减法 高精度乘法 高精度除法 c/c++ java
- hdu 3936 FIB Query 菲波拉切数列的性质+矩阵乘法
- 大数乘法和大数除法模板
- [ACM] hdu 1134 Game of Connections(大数+Catalan数)
- 大数运算,队列实现大数 加法、乘法、除法、模除
- hdu 1261 (大数除法)
- [ACM] hdu 1134 Game of Connections(大数+Catalan数)