GNY 2015 Running Steps
来源:互联网 发布:ubuntu卸载nvidia驱动 编辑:程序博客网 时间:2024/06/10 01:33
Problem description
The coach wants his team members to run up the stadium steps taking either one or two steps with each stride so that:
a) The number of two step strides taken by each leg is the same.
b) The number of one step strides taken by each leg is the same.
c) The number of two step strides is no smaller than the number of one step strides.
d) Start with the left leg.
The coach wants to know for a given (necessarily even) number of steps how many different ways there are to run the steps and satisfy his rules.
For this problem, you will write a program that calculates the number of different ways there are to run the steps that satisfy the coach’s four criteria.
Input
The first line of input contains a single integer P, (1 ≤ P ≤10000), which is the number of data sets that follow. Each data set should be processed identically and independently.
Each data set consists of a single line of input. It contains the data set number, K, followed by an even integer which is the total number of steps to be run, S, (2 ≤ S ≤ 100).
Output
For each data set there is a single line of output. The single output line consists of the data set number, K, followed by a single space followed by the number of different ways of running the steps that satisfy the coach’s four criteria.
Sample Input
51 62 83 104 125 60Sample Output
1 42 13 94 375 40197719157
本题的题意是一个教授训练一群学生走阶梯
其中左脚开始走,每次迈腿可以走一步或者两步
要求走到目标点时满足:
左脚走2步的步数等于右脚走2步的步数,
左脚走1步的步数等于右脚走1步的步数
走2步的次数大于等于走1步的次数
求出所有的方案。
思路是:因为迈2步的步数要大于等于1步的,直接从所有路按两步走开始
然后求1 2的排列组合 然后两步次数减一 一步次数加二继续算
知道走1步次数大于走2步便输出结果
代码如下:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;long long int a[55][55];void init(){ a[0][0]=a[1][0]=a[1][1]=1; for(int i=2;i<=50;i++){ a[i][0]=1; for(int j=1;j<=i;j++) a[i][j]=a[i-1][j-1]+a[i-1][j]; }}int main(){ init(); int t; cin>>t; while(t--){ int k,n; cin>>k>>n; int x=n/2,y=0; if(x%2){ x--; y+=2; } long long int ans=0; while(x>=y){ long long int tmp=a[x/2+y/2][y/2]; ans+=(tmp*tmp); x-=2; y+=4; } cout<<k<<" "<<ans<<endl; } return 0;}
- GNY 2015 Running Steps
- 【Uestc 1423 Running Steps】+ 排列组合
- Steps
- Steps
- Steps
- Steps
- Steps
- Steps
- Steps
- steps
- Steps
- steps
- Moses Running Process and Steps :Moses运行过程记录---Moses运行前的准备(一)
- The steps of running Sencha on BlackBerry z10, BB10运行Sencha的步聚
- running
- ZOJ.1871 Steps【水,”英语题“】 2015/09/22
- Poj.2590 Steps【“英语题”,水】 2015/09/22
- Number Steps
- **MYSQL** 系列一
- 大数据基础(五)从零开始安装配置Hadoop 2.7.2+Spark 2.0.0到Ubuntu 16.04
- Uva 1225 - Digit Counting
- 组合数
- RecyclerView替代listview
- GNY 2015 Running Steps
- Java生成验证码(二) 使用Kaptcha组件生成图片验证码
- EventBus 3.0 深入了解
- POJ 2533 Longest Ordered Subsequence
- CodeForces 346A
- 从上到下逐层打印一棵树
- Linux学习之路(一)
- Java 专业人士必备的书籍和网站列表
- eclipse 安装svn插件