
POJ
一只会旅行的猫
这个作者很懒,什么都没留下…
展开
-
poj 1703 Find them, Catch them
http://poj.org/problem?id=1703 题意:有两个不同的敌对帮派,判断它们的关系,敌对的敌对即朋友,种类并查集 #include #include using namespace std; const int N=100005; int father[N],rank[N]; int Find(int x) { if(x==father[x]) return fa原创 2013-04-21 19:54:34 · 601 阅读 · 0 评论 -
【最大流(dinic)】poj 1273 Drainage Ditches
http://poj.org/problem?id=1273 分析:最大流的dinic实现模板(邻接矩阵) #include #include #include #include using namespace std; const int NM=205; const int MAX=0xfffffff; int a[NM][NM],level[NM],n,m; inlin原创 2014-02-18 12:35:59 · 503 阅读 · 0 评论 -
poj 3032 Card Trick
http://poj.org/problem?id=3032 分析:如下图,模拟翻牌的过程 #include #include #include #include using namespace std; int main() { int T,i,j,n,t,a[20]; dequedq1; scanf("%d",&T); while(T--) { dq1.cl原创 2014-03-06 13:54:54 · 583 阅读 · 0 评论 -
【Bellman_Ford】poj 1860 Currency Exchange
http://poj.org/problem?id=1860 题意:A和B交换率相等(双向图),每次交换需要小费(可以交换多次),问经过一系列交换后(最后需要换回最开始的那种货币),资金能否增长? 分析:寻找正权回路 #include #include #include #include #include using namespace std; const int原创 2014-03-27 19:29:32 · 658 阅读 · 0 评论 -
【DFS】poj 1564 Sum It Up(hdu 1258)
http://poj.org/problem?id=1564 分析:注意保存上一次加上的数,用以判断是否重复 #include #include #include #include using namespace std; const int NM=15; int a[NM],vis[NM],save[NM],n,tol; bool flag; bool comp(in原创 2013-06-12 17:02:00 · 614 阅读 · 0 评论 -
【DFS(记忆化)】poj 1351 Number of Locks
http://poj.org/problem?id=1351 题意:原创 2014-04-16 18:31:40 · 520 阅读 · 0 评论 -
poj 1664 放苹果
http://poj.org/problem?id=1664原创 2014-04-17 19:35:31 · 446 阅读 · 0 评论 -
【BFS+Prim】poj 3026 Borg Maze
http://poj.org/problem?id=3026 题意:从S开始找到一条到所有外星人A的通路,使得该通路总长度最短。 分析:暴搜找出所有A/S之间的边,然后用prim把所有最短的边连接起来。 #include #include #include #include using namespace std; const int NM=105; /*k:外星人的个数,原创 2014-03-26 20:53:18 · 479 阅读 · 0 评论 -
【字典树】poj 1204 Word Puzzles(外:poj Shortest Prefixes)
http://poj.org/problem?id=1204 分析:对要查找的单词建立字典树,然后对table进行顺序遍历,查找方向:A~H(A:north) #include #include #include using namespace std; const int NM=1005; char str[NM][NM],sw[NM][NM]; int a[NM][3],n,m原创 2014-01-23 16:26:40 · 581 阅读 · 0 评论 -
【拓扑排序】poj 1094 Sorting It All
http://poj.org/problem?id=1094原创 2014-05-17 17:57:41 · 454 阅读 · 0 评论 -
【DFS(记忆化)】hdu 1078 FatMouse and Cheese(poj 1088 滑雪)
#include #include #include #include using namespace std; const int NM=105; int a[NM][NM],vs[NM][NM],n,k,mmax; int d[4][2]={-1,0,1,0,0,-1,0,1}; int max(int x,int y){ return x>y?x:y原创 2014-04-10 17:20:01 · 560 阅读 · 0 评论 -
【KMP(循环节)】poj 2406 Power Strings(外:hdu 1358 Period)
http://poj.org/problem?id=2406 #include #include #include using namespace std; const int NM=10000005; int next[NM]; char str[NM]; void get_next(){ int i,j,len; len=strlen(str); i=0;next原创 2014-05-12 20:01:18 · 526 阅读 · 0 评论 -
【并查集+字典树】poj2513 Colored Sticks
http://poj.org/problem?id=2513 分析:形成欧拉通路,即:无向图每个点的度数为偶数或有2个奇数,Trie+并查集 欧拉回路的定义;图G的一个回路,若它恰通过G中每条边一次,则称该回路为欧拉(Euler)回路,具有欧拉回路的图称为欧拉图(简称E图)。 类似:NYOJ42 一笔画问题 #include #include #include using name原创 2013-04-28 20:13:54 · 686 阅读 · 0 评论 -
【DFS】poj 1426 Find The Multiple
http://poj.org/problem?id=1426 #include #include #include using namespace std; typedef __int64 LL; const int NM=205; int n,vis[NM]; LL BFS(){ queueq1; LL t=1,x1,x2; int mod1,mod2; memse原创 2014-05-23 17:23:15 · 639 阅读 · 0 评论 -
【最大流(EK)】poj 1149 PIGS
http://poj.org/problem?id=1149 题意:有M个猪圈、N个顾客,每个顾客有A把钥匙;只能在有钥匙的猪圈购买最多B只猪,顾客购买过后,可以对打开的猪圈内的猪重新分配;求最多可以卖出多少头猪? 分析:经过大神的总结,得以建立以下图: 1)在原先的图中添加源点(0)和汇点(n+1); 2)源点连接的是每个猪圈的第一个顾客,如果一个顾客是多个猪圈的第一名买家,则将权值合并原创 2014-02-17 00:44:28 · 577 阅读 · 0 评论 -
【线段树(线段离散化+lazy)】poj 2528 Mayor's posters
http://poj.org/problem?id=2528 题意:有不同长度([x,y])的海报被贴在一个长墙上,求有多少个海报可以被看到(只要有一部分漏在外面就算) 分析:离散化的时候是对线段而不是对点离散,否则会错误,因为即使是[1,1]也表示一个线段,比如下例: li ri 1 10 1 3 6 10 清除相同项原创 2014-02-09 20:14:52 · 754 阅读 · 0 评论 -
poj 1988 Cube Stacking
http://poj.org/problem?id=1988 题意:把集合cubX放到cubY上方,求任意元素的下方有多少元素 分析:主要是计算每个元素与根节点之间的距离 #include #include using namespace std; const int N=30005; int father[N],rank[N],num[N]; int Find(int x) { if原创 2013-04-22 21:07:44 · 563 阅读 · 0 评论 -
poj 1611
http://poj.org/problem?id=1611 题意:0为传染源,和0在同一集合内的都认定为患者 #include #include #include using namespace std; int father[30005],a[30005],rank[50005]; int Find(int x) { while(x!=father[x]) x=father原创 2013-04-20 20:19:37 · 614 阅读 · 0 评论 -
poj 1182 食物链
http://poj.org/problem?id=1182 分析: rank[x]=(rank[x]+rank[t])%3; rank[t1]=(rank[y]-rank[x]+d-1+3)%3; 参考:http://cavenkaka.iteye.com/blog/1489588 #include #include using namespace std; con原创 2013-04-17 21:32:09 · 649 阅读 · 0 评论 -
poj 1276
http://poj.org/problem?id=1276 题意:有N种不同个数(ni)的不同面值(di)钞票,求满足 #include #include #include using namespace std; const int NUM=100005; int f[NUM]; int main() { int wei[15],num[15],t,i,j,k,cash,N,MAX;原创 2013-05-03 20:45:27 · 592 阅读 · 0 评论 -
poj 2115 C Looooops
http://poj.org/problem?id=2115 #include #include using namespace std; __int64 r,x,y; void EX_Eulid(__int64 a,__int64 b) { if(b==0) { x=1;y=0;r=a; } else { EX_Eulid(b,a%b);原创 2013-05-03 20:01:25 · 485 阅读 · 0 评论 -
poj 1562 Oil Deposits(迷宫)
http://poj.org/problem?id=1562 题意:寻找矿藏的数量,8个方向(上下左右、斜对角)都为相同的一个矿藏 分析:广搜,在有矿藏的地方找寻所有的点 #include #include #include #include using namespace std; int a[102][102],vis[8][2]={-1,0,1,0,0,-1,0,1,-1,1,1,原创 2013-06-09 19:33:33 · 609 阅读 · 0 评论 -
poj 2063 Investment
http://poj.org/problem?id=2063 分析:存入不同的钱会有不同的利息,计算下一年需要 本金+利息,其实这是完全背包(不需要完全装满) #include #include using namespace std; const int NM=1000005; const int MAX=0x3fffffff; int wei[15],add[15],f[NM];原创 2013-09-21 22:14:32 · 688 阅读 · 0 评论 -
poj 3624 Charm Bracelet
http://poj.org/problem?id=3624 题意:01背包 #include #include #include using namespace std; const int NUM=3405; int weight[NUM],vau[NUM],f[12900]; int main() { int i,j,N,M; while(scanf("%d%d",原创 2013-04-03 21:10:40 · 603 阅读 · 0 评论 -
【单调队列】poj 2823 Sliding Windows
http://poj.org/problem?id=2823 #include #include using namespace std; const int NM=1000005; int a[NM],que[NM]; int n,len; void Min_win() { int tail,head,i; head=1; tail=0; for(i=1;i<=len;i+原创 2013-11-17 18:24:36 · 438 阅读 · 0 评论 -
【线段树】poj 2828 Buy Tickets
http://poj.org/problem?id=2828 题意:每个新加入的人,会加入到第pos个人后面,求最后的队列顺序 分析:逆向考虑,比如这组测试数据: pos vau 0 77 1 51 1 33 2 69 第四个人插入后,他的位置就固定了:XX69X;同理,第三个人插入的时候,第四个人对他的位置不会原创 2014-02-05 13:54:57 · 614 阅读 · 0 评论 -
【树状数组(二维)】poj 2155 Matrix
http://poj.org/problem?id=2155 分析:插入区间,求单点 #include #include #include using namespace std; const int NUM=1010; int a[NUM][NUM],N; int lowbit(int x) { return x&(-x); } int sum(int x,int y) {原创 2014-02-05 14:24:27 · 516 阅读 · 0 评论 -
【树状数组(二维)】poj 1195 Mobile phones(外:hdu 2642 Stars)
http://poj.org/problem?id=1195 分析:裸二维树状数组 #include #include #include using namespace std; const int NM=1030; __int64 a[NM][NM]; int lowbit(int x) { return x&(-x); } void add(int x,int y,i原创 2014-01-27 23:10:04 · 647 阅读 · 0 评论 -
【线段树】poj 3264 Balanced Lineup(外:hdu 1754 I Hate It)
http://poj.org/problem?id=3264 题意:求某区间内最大值和最小值的差值 #include #include #include using namespace std; const int NM=50005; struct Tree{ int mmin,mmax; }T[NM*4]; void Build(int lf,int rg,int原创 2014-02-02 22:32:28 · 549 阅读 · 0 评论 -
【线段树(lazy)】poj 2777 Count Color
http://poj.org/problem?id=2777 题意:把长度为L的板子分成L份,标签从1~L,开始时板子的颜色都为1,然后对板子的某一区间涂色,求在某一区间内有多少种不同的颜色?(A可能>B) 分析:区间更新+区间查找 #include #include #include using namespace std; const int NM=100005; i原创 2014-02-09 15:22:28 · 472 阅读 · 0 评论 -
【DFS】poj 1190 生日蛋糕
http://poj.org/problem?id=1190 #include #include using namespace std; const int MAX=0xfffffff; int mmins; int V,M; int Get_minV(int x){ return (x+1)*(x+1)*x*x/4; } /* V=PI*r^2*h; S(侧)=2*PI*r原创 2014-05-23 16:56:51 · 710 阅读 · 0 评论