GDUFE ACM-1001

题目:http://acm.gdufe.edu.cn/Problem/read/id/1001

走楼梯

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

   有一楼梯共M级.刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?

Input:

输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(2<=M<=40),表示楼梯的级数。

Output:

对于每个测试实例,请输出不同走法的数量。

Sample Input:

5
2
3
4
5
39

Sample Output:

1
2
3
5
63245986

思路:这个的结果是一个有规律的数列,套公式an=a(n-1)+a(n-2) (n>2)就可以了。

难度:主要是公式比较难想出来。。。

代码:
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int n,m,i;
 5     int ch[41];
 6     while(scanf("%d",&n)!=EOF)
 7     {
 8         while(n--)
 9         {
10             scanf("%d",&m);
11             ch[2]=1;
12             ch[1]=1;
13             if(m>2)
14             for(i=3;i<=m;i++)
15                 ch[i]=ch[i-1]+ch[i-2];
16             printf("%d\n",ch[m]);
17         }
18     }
19     return 0;
20 }
时间: 2024-10-22 15:42:40

GDUFE ACM-1001的相关文章

[acm 1001] c++ 大数加法 乘法 幂

北大的ACM 1001 poj.org/problem?id=1001 代码纯手动编写 - - 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 6 class BigNumber 7 { 8 struct BigNumberNode 9 { 10 BigNumberNode():n(0), prev(NULL), next(NULL){} 11 BigNumberNode(int N)

ACM 1001

Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series of integers n, one integer per line. Output For each c

acm入门 杭电1001题 有关溢出的考虑

最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series of integers n, one integer per line Output For each case, output SUM(n) in one line

hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)

Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 208    Accepted Submission(s): 101 Problem Description You may not know this but it's a fact that Xinghai Square is

hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878 题目大意: 给出一个数n ,求一个数X, X>=n. X 满足一个条件 X= 2^a*3^b*5^c*7^d 求靠近n的X值. 解题思路: 打表+二分查找 [切记用 cin cout,都是泪...] AC Code: 1 #include<bits/stdc++.h> 2 using namespace std; 3 long long na[100002]; 4 5 int main

ACM学习历程—HDU5585 Numbers(数论 || 大数)(BestCoder Round #64 (div.2) 1001)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5585 题目大意就是求大数是否能被2,3,5整除. 我直接上了Java大数,不过可以对末尾来判断2和5,对所有位的和来判断3. 代码就不粘了.

武汉科技大学ACM :1001: A+B for Input-Output Practice (I)

Problem Description Your task is to Calculate a + b. Too easy?! Of course! I specially designed the problem for acm beginners.  You must have found that some problems have the same titles with this one, yes, all these problems were designed for the s

2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 782    Accepted Submission(s): 406 Problem Description I will show you the most popular board game in the Shanghai Ingress Resis

heu acm基础训练 1001

哈尔滨工程大学 online judge acm训练之分治算法 原题大意:求a ,b,之间的数有多少个1,包括a,b. 这题典型的分治算法: 举例说明: 以197为例: 那么我们将其分为个位,十位,个位7上有一个,那么在190~197上有7+1个 然后整十位上的为18,即197/10-1,然后其权值将变为10.如此进行. 源代码: #include<stdio.h> #define N 11 int d[N],value; int deal(int n) { int one ,ten ; if

2016 ACM/ICPC Asia Regional Qingdao Online 1001 I Count Two Three

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description I will show you the most popular board game in the Shanghai Ingress Resistance Team.It all star