- 博客(10)
- 资源 (1)
- 收藏
- 关注
原创 爬楼梯
<br />/* 爬楼梯问题:每次可以跨上1…M个台阶,一共有N个台阶,问从最底下爬到最高处有几种爬法 */#include <stdio.h>#define MAX 100/* 共n个台阶,每次最多m个台阶,f[i]保存爬n个台阶的爬法总数,返回f[n] * 优化版O(n) */long long PaLouTi(const int n, const int m, long long * const f){ int i; f[0] = f[1] = 1; for
2011-03-30 23:08:00 1300
原创 关于爬楼梯问题的解法
/* 爬楼梯问题:每次可以跨上1…M个台阶,一共有N个台阶,问从最底下爬到最高处有几种爬法 */#include #define MAX 100/* 共n个台阶,每次最多m个台阶,f[i]保存爬n个台阶的爬法总数,返回f[n] * 优化版O(n) */long long PaLouTi(const int n, const int m, long long * const f){ int i; f[0] = f[1] = 1; for (i = 2; i
2010-08-02 18:54:00 3745 1
原创 PKU 1862 Stripies
通过这道题学会了简单的使用STL中的优先级队列priority_queue。题目大意:给定一个包含若干个数的集合,每次抽出两个数a和b,通过公式2*sqrt(a*b)得到的新值放回集合。直到集合中剩余1个元素。求这个“剩余元素”的最小值。思路:通过简单的推导,容易知道:若想使得“剩余元素”值最小,每次抽出的两个数a和b值要最大。所以想到了“大根堆”这种数据结构。#include #include #include #include #include #include #include
2010-07-08 18:57:00 597
原创 PKU 2190 ISBN
特别注意'X':(1) 当问号出现在末尾,它可能是0~9,X(2) 当问号出现在其它位置,它可能是0~9,不可以是X#include #include #include #include #include #include using namespace std;int main(){ char str[20]; gets(str); int q; int sum = 0; for (int i = 0; i
2010-07-07 12:57:00 580
原创 PKU 1657 Distance on Chessboard
<br />注意起点与终点相同的情况<br />/* 1657 Distance on Chessboard */#include <iostream>#include <cstdio>#include <cstdlib>#include <string>#include <cmath>using namespace std;int max(int a, int b){ return a > b ? a : b;}int main(){ int x1, y
2010-07-06 13:53:00 527
原创 PKU 1552 Doubles
先排序#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;int main(){ int num[100]; cin >> num[0]; while (num[0] !=
2010-07-06 13:42:00 472
原创 PKU 2136 Vertical Histogram
<br />使用strncpy去除后面的空格<br />/* 2136 Vertical Histogram */#include <iostream>#include <cstdio>#include <cstdlib>#include <cctype>#include <string>#include <cstring>using namespace std;inline void RemoveEndSpace(char * str1, char * str2){
2010-07-06 13:38:00 406
原创 PKU 2419 Forest
<br />使用了bitset解决<br />/* 2419 Forests */#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <bitset>using namespace std;const int MAX = 105;int main(){ bitset<MAX> person[MAX]; int per, tree; int a, b;
2010-07-06 13:36:00 589
SGU离线题库(完整530道题,带试题难度排序)
2011-06-21
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人