2013年7月6日
摘要:
题目链接。分析:数论了解的还不算太多,解的时候,碰到了不小的麻烦。设答案为x,n = (1#include #include #include #include #include #include #include #include #include using namespace std;typedef long long LL;void gcd(LL a, LL b, LL &d, LL &x, LL &y) { if(!b) { d = a; x = 1; y = 0; } else { gcd(b, a%b, d, y, x); y-= x*(a/b); }}i
阅读全文
posted @ 2013-07-06 15:37
Still_Raining
阅读(758)
推荐(0)
2013年7月4日
摘要:
原文链接:http://news.cnblogs.com/n/125826/ 编者按:2008年 8 月 4 日,StackOverflow 网友Bert F发帖提问:哪本最具影响力的书,是每个程序员都应该读? “如果能时光倒流,回到过去,作为一个开发人员,你可以告诉自己在职业生涯初期应该读一本,你会选择哪本书呢?我希望这个书单列表内容丰富,可以涵盖很多东西。” 很多程序员响应,他们在推荐时也写下自己的评语。以前就有国内网友介绍这个程序员书单,不过都是推荐数 Top 10 的书。其实除了前 10 本之外,推荐数前 30 左右的书籍都算经典,伯乐在线整理编译这个问答贴,同时摘译部分推荐人的...
阅读全文
posted @ 2013-07-04 20:33
Still_Raining
阅读(265)
推荐(0)
摘要:
题目链接。分析:暂略。AC代码:#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 510;int n;bool G[maxn][maxn];int linker[maxn];bool used[maxn];bool dfs(int u) { for(int v=0; v<n; v++) if(G[u][v] && !used[v]) { used[v] = true; i...
阅读全文
posted @ 2013-07-04 20:24
Still_Raining
阅读(229)
推荐(0)
2013年7月3日
摘要:
题目链接。分析:比POJ2253要简单些。AC代码:#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 550;const int INF = (1= d[y]) m = d[x=y]; vis[x] = true; for(int y=0; y#include #include #include #include #include #include #include #include...
阅读全文
posted @ 2013-07-03 22:34
Still_Raining
阅读(214)
推荐(0)
摘要:
题目链接。题意:从0号点,到1号点,找一条能通过的路,使得这条路中的最大的边,比其它所有可能的路中的边都小。分析:这题就是按着dijkstra写,写着写着觉得像是prim了。其中d[n]表示从0出发到达该点的某条路中的最大边,且比其它可能的路中的都小。从d[i]到d[j], 就是要用 max(d[i], G[i][j]) 去更新 d[j] 。注意:输出时要用 %.3f 不能用 %.3lf.#include #include #include #include #include #include #include #include #include #include using namespac
阅读全文
posted @ 2013-07-03 17:03
Still_Raining
阅读(3601)
推荐(0)
摘要:
题目链接。题意:根据汇率可以将一种金币换成其他的金币,求最后能否赚到比原来更多的金币。分析:最短路的求法,用floyd.#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 100;map a;double G[maxn][maxn];int cn ;int main() { int n, m, u, v, cnt = 0; char s[1000], s1[1000], s2[1000]; do...
阅读全文
posted @ 2013-07-03 13:37
Still_Raining
阅读(206)
推荐(0)
2013年6月30日
摘要:
题目链接。题意:找一个n,和一个m(m #include #include #include #include #include #include #include using namespace std;typedef unsigned long long int LL;int main() { freopen("my.txt", "w", stdout); int cnt = 0; for(LL n=8; cnt #include #include using namespace std;char a[][40] = {" 6 ...
阅读全文
posted @ 2013-06-30 17:15
Still_Raining
阅读(558)
推荐(0)
摘要:
题目链接。题意:给定两个数,一个G,一个L,找出两个数a,b(a#include #include #include #include #include #include using namespace std;const int maxn = 100+10;typedef long long LL;int main() { // freopen("my.txt", "r", stdin); int T; LL G, L; scanf("%d", &T); while(T--) { while(cin >> G &
阅读全文
posted @ 2013-06-30 10:50
Still_Raining
阅读(283)
推荐(0)
2013年6月28日
摘要:
题目链接。分析:状态转移方程 d[i][j] = max(d[i-1][j], d[i+1][j], d[i][j-1], d[i][j+1])。#include #include #include #include #include #include #include using namespace std;const int maxn = 100+10;int a[maxn][maxn], d[maxn][maxn], n, m;int dx[] = {0, 0, -1, 1};int dy[] = {-1, 1, 0, 0};int dfs(int x, int y) { if(d...
阅读全文
posted @ 2013-06-28 09:56
Still_Raining
阅读(393)
推荐(0)
摘要:
题目链接。分析:水题一道。#include #include #include #include #include #include #include using namespace std;int cmp(double x, double y) { if(x-y> n) { if(n == 0) break; int item = 2; double sum = 0; while(cmp(sum, n) == -1) { sum += 1.0/item; item++; }...
阅读全文
posted @ 2013-06-28 08:41
Still_Raining
阅读(218)
推荐(0)
2013年6月27日
摘要:
题目链接。分析:从左向右求一遍LIS,再从右向左求一遍LIS,最后一综合,就OK了。注意:有一种特殊情况(详见discuss):83 4 5 1 2 5 4 3答案是:2AC代码如下:#include #include #include #include #include using namespace std;const int maxn = 1000 + 10;const double INF = 1e100;double a[maxn];int d1[maxn], d2[maxn];\int main() { int n;// freopen("my.txt", &q
阅读全文
posted @ 2013-06-27 21:59
Still_Raining
阅读(675)
推荐(0)
摘要:
题目链接。分析:一开始以为简单的DFS,直接做,MLE了。本体应该用最短路径(Dijkstra算法)做。此题的关键在于等级限制的处理,采用枚举,即假设酋长等级为5,等级限制为2,那么需要枚举等级从3~5,4~6,5~7从满足改等级范围的结点组成的子图中用Dijkstra来算出最短路径,最后求出最小值。AC代码如下:#include #include #include #include #include using namespace std;const int maxn = 100+10;const int INF = (1= d[y]) m = d[x=y]; vis[x] =...
阅读全文
posted @ 2013-06-27 13:30
Still_Raining
阅读(185)
推荐(0)
2013年6月25日
摘要:
题目链接。题意:先沿着左边的墙从 S 一直走,求到达 E 的步数。再沿着右边的墙从 S 一直走,求到达 E 的步数。最后求最短路。分析:最短路好办,关键是沿着墙走不太好想。但只要弄懂如何转,这题就容易了。单就沿着左走看一下:当前方向 检索顺序 ↑: ←↑→↓ →: ↑→↓← ↓ : →↓←↑ ←: ↓←↑→如此,规律很明显,假设数组存放方向为←↑→↓, 如果当前方向为↑, 就从← 开始依次遍历,找到可以走的,如果 ← 可以走,就不用再看↑ 了。在DFS时,加一个参数,用来保存当前的方向。#include #include #include #include ...
阅读全文
posted @ 2013-06-25 13:12
Still_Raining
阅读(1901)
推荐(1)
2013年6月22日
摘要:
题目链接。分析:水题。#include #include #include using namespace std;const int maxn = 100;int P[maxn], W[maxn];char s[maxn];int main(){ int T, n, m; scanf("%d", &T); while(T--) { scanf("%d", &n); P[0] = 0; for(int i=1; i=0; j--) { if(s[j] == ')') { t++; ls_cnt++...
阅读全文
posted @ 2013-06-22 14:43
Still_Raining
阅读(164)
推荐(0)
摘要:
题目链接。分析:很简单的一道题,#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <stack>#include <cmath>#include <queue>using namespace std;const int maxn = 100;int dx[] = {-1, 0, 1, 0};//上右下左int dy[] = {0, 1, 0, -1};char G[maxn][maxn];int st
阅读全文
posted @ 2013-06-22 00:25
Still_Raining
阅读(238)
推荐(0)
2013年6月21日
摘要:
题目链接。分析:虽说是简单的模拟,却调试了很长时间。调试这么长时间总结来的经验:1.坐标系要和题目建的一样,要不就会有各种麻烦。2.在向前移动过程中碰到其他的机器人也不行,这个题目说啦:a robot always completes its move before the next one starts moving。#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 100 + 10;int G[maxn][maxn];int
阅读全文
posted @ 2013-06-21 20:59
Still_Raining
阅读(725)
推荐(0)
摘要:
题目链接。分析:最多有五个变量,所以枚举所有的真假值,从后向前借助于栈验证是否为永真式。#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <stack>using namespace std;const int maxn = 10000 + 10;stack<bool> S;char s[maxn];bool hash[200], ans;void check(char pos) { if(s[pos] == &
阅读全文
posted @ 2013-06-21 10:41
Still_Raining
阅读(679)
推荐(0)
2013年6月19日
摘要:
题目链接。分析:模拟。果然模拟什么的最讨厌了。用e1,e2分别记录队列1,队列2的结束时间。每个结点的s记录开始时间,e一开是记录逗留时间,进队列的时候,改成离开的时间。时刻记录总时间就可以了。#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <vector>using namespace std;const int maxn = 1000 + 10;struct node {
阅读全文
posted @ 2013-06-19 22:26
Still_Raining
阅读(798)
推荐(1)
摘要:
题目链接。分析:转换成表达式树,然后先序、中序、后序遍历。AC代码如下:#include <stdio.h>#include <string.h>#define maxn 1000int lch[maxn], rch[maxn], nc = 0;char op[maxn];int build_tree(char *s, int x, int y) { int i, c1 = -1, c2 = -1, p = 0; int u; if(y-x == 1) { u = ++nc; lch[u] = rch[u] = 0; op[u] = s[x]; ...
阅读全文
posted @ 2013-06-19 19:06
Still_Raining
阅读(442)
推荐(0)
2013年6月17日
摘要:
题目链接。分析:给定 n 个点和 m 条无项边,求连通分量的数量。用并查集很简单。#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <map>#include <queue>#include <cmath>using namespace std;const int maxn = 50000 + 10;int p[maxn];int find(int
阅读全文
posted @ 2013-06-17 10:54
Still_Raining
阅读(170)
推荐(0)