随笔分类 -  acm

上一页 1 2 3 4 5 6 7 8 下一页
POJ2485 Highways(最小生成树)
摘要:题目链接。分析:比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)
POJ2253 Frogger(最短路)
摘要:题目链接。题意:从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) 评论(2) 推荐(0)
POJ2240 Arbitrage(最短路)
摘要:题目链接。题意:根据汇率可以将一种金币换成其他的金币,求最后能否赚到比原来更多的金币。分析:最短路的求法,用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) 推荐(0)
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 阅读(558) 评论(0) 推荐(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 阅读(283) 评论(0) 推荐(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 阅读(393) 评论(0) 推荐(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 阅读(218) 评论(0) 推荐(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 阅读(675) 评论(0) 推荐(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 阅读(185) 评论(0) 推荐(0)
POJ3083 Children of the Candy Corn(搜索)
摘要:题目链接。题意:先沿着左边的墙从 S 一直走,求到达 E 的步数。再沿着右边的墙从 S 一直走,求到达 E 的步数。最后求最短路。分析:最短路好办,关键是沿着墙走不太好想。但只要弄懂如何转,这题就容易了。单就沿着左走看一下:当前方向 检索顺序 ↑: ←↑→↓ →: ↑→↓← ↓ : →↓←↑ ←: ↓←↑→如此,规律很明显,假设数组存放方向为←↑→↓, 如果当前方向为↑, 就从← 开始依次遍历,找到可以走的,如果 ← 可以走,就不用再看↑ 了。在DFS时,加一个参数,用来保存当前的方向。#include #include #include #include ... 阅读全文
posted @ 2013-06-25 13:12 Still_Raining 阅读(1901) 评论(0) 推荐(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 阅读(163) 评论(0) 推荐(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 阅读(724) 评论(0) 推荐(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 阅读(679) 评论(0) 推荐(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 阅读(798) 评论(0) 推荐(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 阅读(442) 评论(0) 推荐(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 阅读(170) 评论(0) 推荐(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 阅读(249) 评论(0) 推荐(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 阅读(246) 评论(0) 推荐(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 阅读(238) 评论(0) 推荐(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 阅读(284) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 下一页