Paths on a Grid 1942 (数学几何)
2015-09-26 17:13
423 查看
Paths on a GridTime Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d& %I64uSubmit StatusDescriptionImagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's explaining that (a+b) 2=a 2+2ab+b 2). So you decide to wasteyour time with drawing modern art instead. Fortunately you have a piece of squared paper and you choose a rectangle of size n*m on the paper. Let's call this rectangle together with the lines it contains a grid. Starting at the lower left corner of the grid, you move your pencil to the upper right corner,taking care that it stays on the lines and moves only to the right or up. The result is shown on the left: Really a masterpiece, isn't it? Repeating the procedure one more time, you arrive with the picture shown on the right. Now you wonder: how many different works of art can you produce?InputThe input contains several testcases. Each is specified by two unsigned 32-bit integers n and m, denoting the size of the rectangle. As you can observe, the number of lines of the corresponding grid is one more in each dimension. Input is terminated by n=m=0.OutputFor each test case output on a line the number of different art works that can be generated using the procedure described above. That is, how many paths are there on a grid where each step of the path consists of moving one unit to the right or one unit up?You may safely assume that this number fits into a 32-bit unsigned integer.Sample Input
5 4 1 1 0 0Sample Output
126 2
#include<stdio.h>#include<string.h>#include<math.h>int main(){unsigned long long n,m,i,j,nn,t;unsigned long long z,x;while(scanf("%I64d%I64d",&n,&m),n|m){z=1;if(n>m){t=n;n=m;m=t;}nn=n+m;for(i=nn,j=1;i>m;i--,j++){x=z*i/j;z=x;}printf("%I64d\n",z);}return 0;}
相关文章推荐
- 电磁场的能量守恒和动量守恒
- Servlet分页技术
- cocos2d-js 3.8监听返回键,进入后台,恢复显示
- 位运算
- keystone_admin_api
- 如何使用Traceroute查询封包所经过的路由器
- 20135231 —— 第二周任务总结报告
- 给ubuntu换个主题
- linux 源码安装php
- Charm Bracelet 3624 (01背包)
- android使用java代码设置textview、button等内容颜色
- Log4j配置详解及不同的包(package)下的日志写入到不同的日志文件下
- Android JSON数据与实体类之间的相互转化-------GSON的用法
- SurfaceView和view分别实现触摸轨迹
- iOS讲解迷惑深入浅出值UICollectionView(集合视图)
- 必须采用初始化列表一共有三种情况
- MySql基本使用方法
- iOS —— JSON 数据结构及其解析方式
- linux redis安装源码包安装
- yum使用,使用rpm指令安装rpm,使用dpkg指令安装deb