Algorithm With Me
文章平均质量分 88
bobten2008
这个作者很懒,什么都没留下…
展开
-
No.1 DP 背包 POJ 1837 Balance
BalanceTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 4100 Accepted: 2369DescriptionGigel has a strange "balance" and he wants to poise it. Actually,原创 2009-04-15 21:10:00 · 945 阅读 · 0 评论 -
poj 1416 Shredding Company
/** * DFS:由于在遍历时,preTemp会随时变化,因此当找到当前最优解时需要用preBest来保存preTemp */#include #include #define MAX_LEN 6using namespace std;int preTemp[MAX_LEN + 1];int preBest[MAX_LEN + 1];int dis[MAX原创 2009-05-31 16:13:00 · 862 阅读 · 0 评论 -
POJ 1090 Chain 递推 + 大数加法
ChainTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2025 Accepted: 684DescriptionByteland had not always been a democratic country. There were also bl原创 2009-08-22 14:02:00 · 2250 阅读 · 0 评论 -
POJ 1091 跳蚤
跳蚤Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3977 Accepted: 1002DescriptionZ城市居住着很多只跳蚤。在Z城市周六生活频道有一个娱乐节目。一只跳蚤将被请上一个高空钢丝的正中央。钢丝很长,可以看作是无限长。节目主持人会给该原创 2009-08-22 22:14:00 · 5119 阅读 · 8 评论 -
POJ 1085 Triangle War
Triangle WarTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1465 Accepted: 582DescriptionTriangle War is a two-player game played on the following trian原创 2009-08-25 17:47:00 · 1922 阅读 · 2 评论 -
POJ Dreisam Equations
DFS + 表达式求值,输入处理很恶心 #include #include #define MAX_N 100using namespace std;int exp[MAX_N + 1];int curExp[MAX_N + 1];int expLen, expVal, curVal;int opType[3] = {-1, -2, -6};bool原创 2009-09-05 22:01:00 · 1473 阅读 · 5 评论 -
POJ 1078
http://acm.pku.edu.cn/JudgeOnline/problem?id=1078这题是典型的DFS回溯题,主要意思是给定两个整数,要求分别对这两个数进行因子分解,因子必须是100以内且不能重复。问,这两个整数是否存在不相交的因子集,例如:24和12,分别可以分解为2 * 12, 3 * 4,所以存在;而49和343就不行了,49不能分解(否则有7重复了),343只原创 2009-09-04 13:34:00 · 1222 阅读 · 0 评论 -
POJ 1101 The Game
/*http://acm.pku.edu.cn/JudgeOnline/problem?id=1101这道题主要采用BFS的变体版本,核心在于:1)除了需要在队列中保存当前节点的方向,坐标外,还需要保存到达当前节点所需的segment数;2)需要使用一个全局minSeg来记录到达某个节点所需的最少segment数,当新的seg 入队列。只保留seg 为d2, 如果d1 ==原创 2009-09-06 16:02:00 · 1094 阅读 · 0 评论 -
POJ 1103 Maze
/* dfs判断环,建图需要技巧,图变成了三维的(h * w * 2)第三维的2用来表示一个格子被/或者/分 成的两块 核心就是判断环,但是由于这题特殊性使得判断环比较简单;利用分别遍历h * w * 2个点,遍历到的点 设置为visited, 当遇到遍历初始点时且这个初始点不是前驱则表示找到一条环 注意一定要判断是否是前驱,否则会产生判断错误*/#原创 2009-09-07 13:51:00 · 1291 阅读 · 0 评论 -
poj 1104 Robbery
/*递推题,好几处需要证明,从而可以简化问题,助于理解1)首先根据输入对tag数组进行设置,处于输入范围内的地方填入1,表示此处不可能出现盗贼,其他地方均填为02)开始递推扫描,经证明,只要一次正向和一次反向递推就可以了,以正向递推为例(反向递推同理),对于时刻t的x,y处,如果已经为1则不用处理,否则,考虑t-1时刻的(x, y), (x - 1, y), (x + 1, y),原创 2009-09-08 17:41:00 · 1770 阅读 · 0 评论 -
POJ 1113 WALL
WallTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 13254 Accepted: 4217DescriptionOnce upon a time there was a greedy King who ordered his chief Arc原创 2009-09-13 15:09:00 · 876 阅读 · 0 评论 -
POJ 1112 Team Them Up
Team Them Up!Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3404 Accepted: 901 Special JudgeDescriptionYour task is to divide a number of persons i原创 2009-09-12 17:39:00 · 1379 阅读 · 0 评论 -
POJ 1119 Start Up the Startup
Start Up the StartupTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1366 Accepted: 346DescriptionClearly the economy is bound to pick up again soon. As原创 2009-09-16 20:20:00 · 1215 阅读 · 0 评论 -
POJ 1123 For the Porsche
For the PorscheTime Limit: 5000MS Memory Limit: 10000KTotal Submissions: 188 Accepted: 67DescriptionThe Cash Cow Consulting Company is challenging the Vice Presiden原创 2009-09-18 21:37:00 · 1309 阅读 · 0 评论 -
POJ 1127 Jack Straws
Jack StrawsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1824 Accepted: 817DescriptionIn the game of Jack Straws, a number of plastic or wooden "st原创 2009-09-19 18:09:00 · 2065 阅读 · 1 评论 -
POJ 1124 Oh, Those Achin' Feet
http://acm.pku.edu.cn/JudgeOnline/problem?id=1124/* 利用DFS回溯求所有最短路径(最短路径可能不止一条) 行走的时候只有当下一个点是终点或者下一点是街道时才可以继续走到下一个点 注意剪枝 注意entrance/exit不参与load,只有街道参与load,即最终结果里凡是非街道结点都要输出0原创 2009-09-19 15:35:00 · 959 阅读 · 0 评论 -
POJ 1126 Simple Syntax
Simply SyntaxTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3300 Accepted: 1472DescriptionIn the land of Hedonia the official language is Hedonian.原创 2009-09-19 16:09:00 · 1175 阅读 · 0 评论 -
POJ 1128 Frame Stacking
/*http://acm.pku.edu.cn/JudgeOnline/problem?id=1128DFS回溯实现拓扑排序*/#include #include #include #include #define MAX_N 32#define MAX_L 26using namespace std;char mapv[MAX_N + 1][M原创 2009-09-20 15:10:00 · 1003 阅读 · 0 评论 -
POJ 1160 Post Office
Post OfficeTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 9376 Accepted: 5027DescriptionThere is a straight highway with villages alongside the highway原创 2009-09-29 17:18:00 · 923 阅读 · 0 评论 -
POJ 1142 Smith Numbers
Smith NumbersTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 7141 Accepted: 2505DescriptionWhile skimming his phone directory in 1982, Albert Wilansky,原创 2009-09-25 22:03:00 · 1176 阅读 · 0 评论 -
POJ 1143 Number Game
/*http://acm.pku.edu.cn/JudgeOnline/problem?id=1143 博弈论(DFS + 状态记忆表 + 位运算), 假定一个走的人是A,第二个走的人是B A在当前状态下一定能够取胜的条件是:当前状态下存在一个数字,对于当A取走 这个数字后的状态,B不管怎么取都得输(即B不能够绝对取胜) 有了上面的分析就很容易看出这是一道博弈题,最终会形原创 2009-09-26 12:04:00 · 2833 阅读 · 0 评论 -
POJ 1137 The New Villa
/*复杂BFS参考了网上别人的程序POJ 上需要SJ,为了避免这个所以需要对输入进行排序*/ #include #include #include #define MAX_S 1024#define MAX_H 10using namespace std;struct statusN{ int rNum, bit, step;原创 2009-09-25 11:11:00 · 994 阅读 · 0 评论 -
POJ 1141 Brackets Sequence
Brackets SequenceTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13305 Accepted: 3585 Special JudgeDescriptionLet us define a regular brackets seque原创 2009-09-25 17:27:00 · 633 阅读 · 0 评论 -
POJ 1201 Intervals
/*第一个差分约束系统(1)如果采用最长路径求法,则求出来的是所有可行解组中最小的(2)如果采用最短路径求法,则求出来的是所有可行解组中最大的由于本题求最小值,因此采用解法2*/#include #include #define MAX_E 50005#define MIN_VAL -1000000#define maxv(a, b) ((a) >= (b原创 2009-10-05 12:02:00 · 761 阅读 · 0 评论 -
POJ 1816 Wild Words
/*http://acm.pku.edu.cn/JudgeOnline/problem?id=1816trie树下的DFS, 感觉非常好的一道题,能说明很多问题*/#include #include #define MAX_M 100000using namespace std;//输入的pattern数以及待匹配的单词数int pNum, strNum原创 2009-10-05 16:04:00 · 1130 阅读 · 4 评论 -
POJ 3468 A simple problems with Integers
A Simple Problem with IntegersTime Limit: 5000MS Memory Limit: 131072KTotal Submissions: 11583 Accepted: 2756Case Time Limit: 2000MSDescriptionYou hav原创 2009-10-05 19:49:00 · 707 阅读 · 1 评论 -
POJ 1961 Period
/*这题考察对next数组的理解next数组中的j本质上维护了从距离i最近的上一个重复串中与i对应的位置因此如果i % (i - j) == 0 && i / (i - j ) > 1则这个刚好扫描到了重复的串*/#include #define MAX_N 1000000char input[MAX_N + 3];int next[MAX_N + 1];i原创 2009-10-06 16:44:00 · 878 阅读 · 0 评论 -
POJ 3630 Phone List
/*Trie树,一开始用的class, new, delete等面向对象的东西,结果TLE后来改用数组实现就OK了这题只需要insert操作,无需search操作,边插入边判断就OK了*/#include #define MAX_N 120000using namespace std;int trieTree[MAX_N + 1][12]; //第10位是I原创 2009-10-05 13:16:00 · 965 阅读 · 0 评论 -
POJ 3283 Card Hands
/*http://acm.pku.edu.cn/JudgeOnline/problem?id=3283Trie树,最终插入的结点的数量状态不好写code就是恶心,这么简单的题,犯了那么多恶心的错误*/#include #define MAX_N 100100using namespace std;int trieTree[MAX_N + 1][13][4];原创 2009-10-05 14:31:00 · 815 阅读 · 0 评论 -
POJ 1152 An Easy Problem
An Easy Problem!Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 6264 Accepted: 1429DescriptionHave you heard the fact "The base of every normal number原创 2009-09-28 12:51:00 · 1077 阅读 · 0 评论 -
POJ 1144 Network
/*并查集求割点*/#include #include #define MAX_N 100#define MAX_L 4950using namespace std;struct line{ int id1, id2; bool have(int id) { if(id != id1 && id != id2)原创 2009-09-26 16:23:00 · 882 阅读 · 0 评论 -
POJ 1145 Tree Summing
/*递归的应用*/#include #include #define MAX_N 1000using namespace std;int len, dest;string curStr;bool found = false;bool isDigit(char ch){ return ((ch >= 0 && ch }int ch原创 2009-09-26 17:54:00 · 961 阅读 · 0 评论 -
POJ 1149 PIGS
/* Tagadmonds karp求网络最大流这题建图的方法很重要:1)对于client i,所有i先到达的猪圈的猪的数量和作为0和i之间的权值2)对于client i,如果其可到的猪圈k已经被另一个client j先到给占了,那么将j 到 i 的边的权值设置为无穷大3)对于client i,i 到 clientNum + 1(终点)的权值设为i可以买的最多的猪的数量4)原创 2009-09-27 19:37:00 · 622 阅读 · 0 评论 -
POJ 1151 Atlantis
/*http://acm.pku.edu.cn/JudgeOnline/problem?id=1151离散化方法思想是将整个地图划分为最小的子方格,然后将子方格的面积相加即可得到最终结果1)首先分别将输入数据的x坐标和y坐标保存到x和y数组里面,然后对这两个数组排序2)然后遍历所有矩形,对于矩形(x1, y1)(x2, y2), 分别遍历x数组和y数组,对于所有满足满足原创 2009-09-28 09:20:00 · 786 阅读 · 0 评论 -
POJ 1179 Polygon
PolygonTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2770 Accepted: 1129DescriptionPolygon is a game for one player that starts on a polygon with N ve原创 2009-10-03 20:10:00 · 673 阅读 · 0 评论 -
POJ 1177 PICTURE
PictureTime Limit: 2000MS Memory Limit: 10000KTotal Submissions: 5093 Accepted: 2644DescriptionA number of rectangular posters, photographs and other pictures of原创 2009-10-05 11:54:00 · 1380 阅读 · 2 评论 -
POJ 2352 STARS
StarsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 12897 Accepted: 5533DescriptionAstronomers often examine star maps where stars are represented by原创 2009-10-05 21:33:00 · 662 阅读 · 0 评论 -
poj 1170 shopping offers
Shopping OffersTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2286 Accepted: 866DescriptionIn a shop each kind of product has a price. For example, th原创 2009-10-03 13:09:00 · 715 阅读 · 0 评论 -
POJ 1178 Camelot
CamelotTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1264 Accepted: 588DescriptionCenturies ago, King Arthur and the Knights of the Round Table use原创 2009-10-03 16:12:00 · 1047 阅读 · 0 评论 -
POJ 1204 World Puzzles
/*http://acm.pku.edu.cn/JudgeOnline/problem?id=1204第一次用Trie树,这题算是比较折腾了,遇到的问题如下1)一开始的思路是对输入图枚举每一个位置及每一个方向插入到trie树中,然后对每一个待搜索单词进行搜索,结果MLE2)思考了一下如果按1)的方法插入数据量太大,MLE也是情理之中的,接着换了思路为何不逆向来,这次是将待搜原创 2009-10-05 11:51:00 · 776 阅读 · 0 评论