UVA138 Street Numbers(数论)
摘要:题目链接。题意:找一个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
阅读(560)
推荐(0)
UVA11388 GCD LCM(数论)
摘要:题目链接。题意:给定两个数,一个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
阅读(288)
推荐(0)
POJ1088 滑雪(记忆化搜索)
摘要:题目链接。分析:状态转移方程 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
阅读(395)
推荐(0)
POJ1003 Hangover
摘要:题目链接。分析:水题一道。#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
阅读(220)
推荐(0)
POJ1836 Alignment(LIS)
摘要:题目链接。分析:从左向右求一遍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
阅读(679)
推荐(0)
POJ1062 昂贵的聘礼(最短路)
摘要:题目链接。分析:一开始以为简单的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
阅读(187)
推荐(0)
POJ3083 Children of the Candy Corn(搜索)
摘要:题目链接。题意:先沿着左边的墙从 S 一直走,求到达 E 的步数。再沿着右边的墙从 S 一直走,求到达 E 的步数。最后求最短路。分析:最短路好办,关键是沿着墙走不太好想。但只要弄懂如何转,这题就容易了。单就沿着左走看一下:当前方向 检索顺序 ↑: ←↑→↓ →: ↑→↓← ↓ : →↓←↑ ←: ↓←↑→如此,规律很明显,假设数组存放方向为←↑→↓, 如果当前方向为↑, 就从← 开始依次遍历,找到可以走的,如果 ← 可以走,就不用再看↑ 了。在DFS时,加一个参数,用来保存当前的方向。#include #include #include #include ...
阅读全文
posted @
2013-06-25 13:12
Still_Raining
阅读(1908)
推荐(1)
POJ1068 Parencodings(模拟)
摘要:题目链接。分析:水题。#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
阅读(173)
推荐(0)
POJ1573 Robot Motion(模拟)
摘要:题目链接。分析:很简单的一道题,#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
阅读(245)
推荐(0)
POJ2632 Crashing Robots(模拟)
摘要:题目链接。分析:虽说是简单的模拟,却调试了很长时间。调试这么长时间总结来的经验: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
阅读(731)
推荐(0)
POJ3295 Tautology(枚举)
摘要:题目链接。分析:最多有五个变量,所以枚举所有的真假值,从后向前借助于栈验证是否为永真式。#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
阅读(686)
推荐(0)
SDUT2087 离散事件模拟-银行管理(模拟)
摘要:题目链接。分析:模拟。果然模拟什么的最讨厌了。用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
阅读(802)
推荐(1)
SDUT2484 算术表达式的转换(表达式树)
摘要:题目链接。分析:转换成表达式树,然后先序、中序、后序遍历。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
阅读(447)
推荐(0)
POJ2524 Ubiquitous Religions(并查集)
摘要:题目链接。分析:给定 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
阅读(175)
推荐(0)
POJ1328 Radar Installation(贪心)
摘要:题目链接。题意:给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住。求最少使用圆的数量。分析:贪心。首先把所有点 x 坐标排序, 对于每一个点,求出能够满足的 最靠右的圆心,即雷达的位置。要保证雷达左面的点都被覆盖,如果不能覆盖就向左移,移到能将左边未覆盖的覆盖。如果后面的店不在雷达的覆盖区,则再加一雷达。#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#includ
阅读全文
posted @
2013-06-16 22:41
Still_Raining
阅读(258)
推荐(0)
POJ2965 The Pilots Brothers' refrigerator(枚举)
摘要:题目链接。题意:给出一个4*4矩阵,每个单元要么是 '+', 要么是 '-',每次可以选一个单元,翻转它以及它所在的行和列。求使全部为'-'的最少操作数,并求出操作步骤。分析:这题和1753类似,但此题的后台数据显然要多余后者。可以利用打表,算出所有的翻转状态。存入sw。打表代码如下:int swc(int i) { int nsw = 0, j; nsw |= (1<<i); j = i; while(j % 4 != 0) { nsw |= (1<<j); j--; } nsw |= (1<<j); j =
阅读全文
posted @
2013-06-16 15:06
Still_Raining
阅读(249)
推荐(0)
POJ3342 Party at Hali-Bula(树形DP)
摘要:题目链接。题意:给定一个树,选择若干点,使得选择的结点中任一结点不会和它的子结点同时选择,求能选结点最大数量。同时判断方案数是否为一。分析:如果单单求最大数量,很容易。之前也做过一个。链接:http://www.cnblogs.com/tanhehe/archive/2013/06/12/3132521.html但是如何判断方案数是否唯一呢?新加一个状态 dup[i][j],表示相应 dp[i][j] 是否唯一方案。对于叶子结点,dup[k][0] = dup[k][1] = 1.对于非叶子结点, 1.对于 i 的任意儿子 j, 若(dp[j][0] > dp[j][1] 且 dup[j
阅读全文
posted @
2013-06-13 21:06
Still_Raining
阅读(239)
推荐(0)
HDU1520 Anniversary party(树形DP)
摘要:题目链接。题意:给定义个多叉树,每个结点上都有一个权值。子结点和父结点不能同时选。求最大的权值和。分析:利用左儿子右兄弟原则转化成二叉树,DP。代码如下:#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;const int maxn = 6000 + 10;struct Tree { int father, child, brother; int Take, Not; void init() { father =
阅读全文
posted @
2013-06-12 11:21
Still_Raining
阅读(286)
推荐(0)
POJ1753 Flip Game
摘要:题目链接。分析:枚举所有的操作。将每个4*4的状态用一个 int 表示, 从0 ~ 15编号。 用BFS 枚举每一种操作。#include <cstdio>#include <cmath>#include <iostream>#include <queue>#include <cstring>using namespace std;const int maxn = (1<<16);const int ntype = (1<<16);queue<int> Q;bool vis[maxn];int st
阅读全文
posted @
2013-06-11 10:51
Still_Raining
阅读(443)
推荐(0)
HDU1211 RSA(数论)
摘要:题目链接。分析:组队赛时做的这题,不得不说,感慨万千。因为题目给的是加密文,要求解密,所以就用M = D(c) = cdmod n。 如何d呢,推了推,觉得d是e的乘法逆。结果没过。后来一商量,觉得ASCII也就那么几个,预处理出来不就完了么?这样,是可以A的,不过在比赛的时候,因为一时疏忽,将一个字母打错(注意是一个字母),一直找BUG。结果没来得及。比赛结束才发现打错了个字母。可恨的是,不论怎么改,样例都过,样例给的真是够“奇妙”的。#include <cstdio>#include <cstring>#include <cstdlib>#include
阅读全文
posted @
2013-06-06 22:49
Still_Raining
阅读(482)
推荐(0)
The Largest SCC(强连通分量)
摘要:题目链接。The Largest SCC题目描述Consider a directed graph with N (1 <= N <= 1000) vertices and M (0 <=M <= 20000) edges. The edges are numbered from 1 to M and the verticesare numbered from 1 to N. Now I will make ONE edge bidirectional, andyou are to tell me the number of vertices of the larges
阅读全文
posted @
2013-06-04 20:09
Still_Raining
阅读(305)
推荐(0)