上一页 1 ··· 9 10 11 12 13 14 15 下一页
摘要: //区间调度/*问题描述:有N项工作,每项工作有开始时间si和结束时间ti,让你选择最多的工作,工作之间不存在时间交叉。输入:51 32 54 76 98 10输出:3*/#include#includeusing namespace std;const int MAX = 100000;int N, s[MAX], t[MAX];//输入,s开始时间,t结束时间pair itv[MAX];//用于对工作排序的pair数组int main(){ cin>>N; int i; for(i=0;i>itv[i].second>>itv[i].first;//便于以结束 阅读全文
posted @ 2013-11-18 20:38 偶尔会寂寞 阅读(1261) 评论(0) 推荐(2) 编辑
摘要: 这样求整的算法真是简洁,因为硬币值最后是1,所以任意余数都能整除掉。如果换成其他问题,末尾不是1空怕就不行了。/*问题描述:硬币问题有1元、5元、10元、50元、100元、500元的硬币,用最少的硬币数来支付A元。*/#includeusing namespace std;const int v[6] = {1, 5, 10, 50, 100, 500};int c[6];//输入硬币个数int A;void solve(){ int ans = 0; for(int i = 5; i >=0; i--){ int t = min(A / v[i], c[i]); ... 阅读全文
posted @ 2013-11-17 23:03 偶尔会寂寞 阅读(214) 评论(0) 推荐(0) 编辑
摘要: /*问题描述:迷宫的最短路径给定N*M的迷宫,找到从起点S到终点G的最短路径长度。(默认一定可以到达终点)输入:10 10#S######.#......#..#.#.##.##.#.#........##.##.####....#....#.#######.#....#......####.###.....#...G#输出:22*/#include#include#define MAX 101using namespace std;const int INF = 100000000;//一般放大2~4倍不会溢出为标准设无穷大值//使用pair表示状态,用typedef会更方便typedef 阅读全文
posted @ 2013-11-17 22:21 偶尔会寂寞 阅读(421) 评论(0) 推荐(0) 编辑
摘要: Lake CountingTime Limit:1000MSMemory Limit:65536KTotal Submissions:16840Accepted:8548DescriptionDue to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 #define MAX 101using namespace std;int N,M;char field[MAX][MAX];void dfs 阅读全文
posted @ 2013-11-17 21:23 偶尔会寂寞 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 深搜解题。/*问题描述:部分和问题给定整数a1,a2....an,判断是否可以从中选出若干数,使它们的和恰好为k。0#define MAX 1000using namespace std;int a[MAX],n,k;bool dfs(int i, int sum){ if(i == n) return sum == k; if(dfs(i +1, sum)) return true; if(dfs(i+1, sum+a[i])) return true; return false;}int main(){ int i; cin>>n>>k; ... 阅读全文
posted @ 2013-11-17 20:54 偶尔会寂寞 阅读(167) 评论(0) 推荐(0) 编辑
摘要: Map和Stack的STL方法简介c++Stack(堆栈)是一个容器类的改编,为程序员提供了堆栈的全部功能,————也就是说实现了一个先进后出的数据结构(FILO);需包含头文件;主要有一下几个函数:empty语法: bool empty();如当前堆栈为空,empty() 函数 返回 true 否则返回false.pop语法: void pop();pop() 函数移除堆栈中最顶层元素。size语法: size_type size();size() 函数返当前堆栈中的元素数目。top语法: TYPE &top();top() 函数返回对栈顶元素的引用.可以通过它访问stack中的每个 阅读全文
posted @ 2013-11-17 20:15 偶尔会寂寞 阅读(694) 评论(0) 推荐(0) 编辑
摘要: 通常求n的斐波那契数,我们就是简单的使用如下的递归函数:int fib1(int n){ if(n#include#define MAX 200using namespace std;int fib1(int n){ if(n<=1) return n; return fib1(n-1)+fib1(n-2);}int memo[MAX+1];int fib2(int n){ if(n<=1) return n; if(memo[n]!=0) return memo[n]; return memo[n] = fib2(n-1)+fib2(n-2);... 阅读全文
posted @ 2013-11-17 20:00 偶尔会寂寞 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 这道题先留着,等我有能力做了我再AC!!!Starship TroopersTime Limit: 10000/5000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4118Accepted Submission(s): 1076Problem DescriptionYou, the leader of Starship Troopers, are sent to destroy a base of the bugs. The base is built underground. I 阅读全文
posted @ 2013-11-17 16:50 偶尔会寂寞 阅读(315) 评论(0) 推荐(0) 编辑
摘要: Tempter of the BoneTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 57248Accepted Submission(s): 15482Problem DescriptionThe doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, 阅读全文
posted @ 2013-11-17 11:33 偶尔会寂寞 阅读(272) 评论(1) 推荐(0) 编辑
摘要: A + B Problem IITime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 177301Accepted Submission(s): 33930Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of 阅读全文
posted @ 2013-11-17 09:44 偶尔会寂寞 阅读(216) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 15 下一页