- 博客(39)
- 资源 (2)
- 问答 (1)
- 收藏
- 关注
原创 Optimal Milking
有一些牛,和一些牛奶站,没个牛奶站每天最多收M只牛奶的牛, 怎样安排可以是所有牛到牛奶站的最长路径最短 思路: 路径最短-》最短路 求最大值最小 -》 二分 牛 -》 牛奶站 多值匹配 but这个题二分取值上限要取好, 开始1000 WA了无数次, 然后去了POJ 的 MESSAGE 改成200000就过了
2015-03-31 07:54:54 310
原创 Jamie's Contact Groups
二分 + 多值匹配 思路:一对多的二分图的多重匹配。二分图的多重匹配算法的实现类似于匈牙利算法,对于集合C中的元素xi,找到一个与其相连的元素yi后,检查匈牙利算法的两个条件是否成立,若yi未被匹配,则将xi,yi匹配。否则,如果与yi匹配的元素已经达到上限,那么在所有与yi匹配的元素中选择一个元素,检查是否能找到一条增广路径,如果能,则让出位置,让xi与yi匹配。二分求出limit,知道
2015-03-27 23:16:53 721
原创 Going Home
最小费用流,我们先求出m到每个H的最短距离, 然后建立一个超级源点SRC和一个超级汇点SINK, 源点到每一个M的流量值为1, H到每个汇点的流量值也是1,然后 m和H之间的流量也是1,这样就保证,他的单价就是 距离的费用, 也确保了一个人只能找一个家 不断用SPFA找增广路,SPFA的距离指标就是费用#include #include #include #in
2015-03-27 23:13:57 314
原创 Dining
裸Dinic模板#include #include #include #include #include using namespace std;#define inf 1000000000#define MAXN 555struct Edge{ int v, f, next;};int n, f, d, src, sink;
2015-03-27 23:10:14 324
原创 Cat VS Dog
这个题转换思维有挺巧妙,我们首先要抽象出两个对立的集合,然后找出他们的关系,其实题中已经有暗示了,他说喜欢狗的人不喜欢的一定是猫,喜欢猫的人一定不喜欢狗,假若我们相用猫狗建图, 那么我们可以向下边的含义是什么呢,是对立关系么,似乎跟我们想求得答案没什么太大关系,那么我们换一个角度,想要开心的人最多,也就是想让不开心的人最少,那么我们把人抽象成图里的点,然后之间有对立关系的我们连线,那么这就是求一个最
2015-03-26 00:08:27 1273
原创 Treasure Exploration
裸地求最大匹配#include #include #include #include using namespace std;#define MAXN 666bool gra[MAXN][MAXN], vis[MAXN];int cx[MAXN], cy[MAXN];int n;bool dfs( int u){ for(int i = 1; i n;
2015-03-26 00:02:25 416
原创 Air Raid
一个有向图,且我们要注意一句话. Each paratrooper lands at an intersection and can visit other intersections following the town streets. 所以我们要先把所有能通向的点都连上边,然后最小点覆盖#include #include #include #include using n
2015-03-26 00:00:57 496
原创 Strategic Game
其实这道题完全可以用树形DP做, 为了练习匹配问题就用匹配做了, 这个就是求最小点覆盖, 就一个裸地求最大匹配然后用N-最大匹配就好了,因为无向,所以双向边,然后求出来的最大匹配/2就是我们真正的匹配数#include #include #include #include #include #include using namespace std;#define MAX
2015-03-25 23:59:20 328
原创 Antenna Placement
就是二分图匹配, 要求把每一个*都能盖上的最小DAir antennas的数目, 那么我们首先先把能共用的数目求出来,就是求最大匹配, 然后用总数减去可以跟别人共用的数目就是我们必须使用的最小数目#include #include #include #include using namespace std;#define MAXN 1000char gr
2015-03-25 00:38:28 324
原创 HDU 2818 Building Block
一个并查集的题, 但是由于要求出每个X下面有多少个石头, 所以我们回退的时候更新,这个一定要注意#include #include #include using namespace std;#define MAXN 33333int fa[MAXN], num[MAXN], down[MAXN];void init(){ for( int i = 0 ; i
2015-03-25 00:08:30 289
原创 Rain on your Parade
这道题其实就是一个Hopcroft-Carp模板题 在匈牙利算法中,我们每次寻找一条增广路来增加匹配集合M.可以证明,每次找增广路的复杂度是O(E),一共需要增广O(V)次,因此总时间复杂度为O(VE).为了降低时间复杂度,在Hopcroft Karp算法中,我们在增加匹配集合M时,每次寻找多条增广路.可以证明,这样迭代次数最多为2*V^0.5,所以,时间复杂度就降到了O(V^0.5*E).
2015-03-25 00:04:49 315
原创 Swap
首先我们要想明白一点,主对角先一定是 i == j 的点是marix[i][j]1, 也就是第I行必须要跟第I列匹配, 那么这道题就变成了一个二分图匹配问题 如果 i行可以跟I列匹配, 那么一定有解, 也就是最大匹配数一定等于矩阵行数 #include #include #include #include #include using namespa
2015-03-25 00:02:33 254
原创 棋盘游戏
就是判断下那个节点会影响匹配,那么我们就依次枚举好了,我们先求出最大匹配,然后以检测点是不是关键点#include#includeint map[105][105],pre[105],vis[105];int n,m;int hungry(int u){ int v; for(v=1;vm;v++) { i
2015-03-24 23:57:15 300
原创 Courses
模板题#include #include #include #include #include using namespace std;#define MAXN 300int match[MAXN];bool vis[MAXN], gra[MAXN][MAXN];int p, n;bool dfs( int x){ for( int i = 1; i n;
2015-03-24 23:55:47 259
原创 The Accomodation of Students
典型的二分图最大匹配题 我们要先判断这个图是不是二分图,可以用染色法来实现#include #include #include #include using namespace std;#define MAXN 222bool gra[MAXN][MAXN], vis[MAXN];int match[MAXN], col[MAXN];int ans, n
2015-03-24 23:54:05 342
原创 Fire Net
#include #include #include using namespace std;char str[5][5];int n, ans;bool check( int x, int y){ for( int i = x - 1; i >= 0; i--) { if(str[i][y] == 'O') return false;
2015-03-24 23:53:02 337
原创 Oil Skimming
很简单一个二分图题,可是我RE+MLE + WA了将近40次百思不得其解的问题当我直接在char 数组上存放序号就是RE, 而当我用另一个数组存放序号就是AC WHY????????RE代码#include #include #include using namespace std;#define MAXN 666char gra[MAXN][MAXN
2015-03-24 23:51:51 287
原创 Knights of the Round Table
点双联通分量+二分图染色1、首先根据题目给出的憎恨关系建图,然后求补图,这个图表示哪个骑士可以和哪个骑士坐在一起。2、在图中求出圈,也就是双联通分量,这可以用到Tarjan算法的思想,通过Tarjan算法执行过程中退栈求出一个又一个双联通分量。3、对于双联通分量我们需要在其中找到一个奇圈,这需要一个利用了DFS的交叉染色法,在代码中我建补图的时候没有建立自己和自己的边,当用这个方法找出来的奇圈
2015-03-21 23:52:38 307
原创 Fire Net
#include #include #include using namespace std;char str[5][5];int n, ans;bool check( int x, int y){ for( int i = x - 1; i >= 0; i--) { if(str[i][y] == 'O') return false;
2015-03-21 23:50:03 242
原创 Courses
裸地二分匹配#include #include #include #include #include using namespace std;#define MAXN 300int match[MAXN];bool vis[MAXN], gra[MAXN][MAXN];int p, n;bool dfs( int x){ for( int i
2015-03-21 23:49:15 274
原创 HDU 4612 Warm up
Description N planets are connected by M bidirectional channels that allow instant transportation. It’s always possible to travel between any two planets through these channels. If we can isolat
2015-03-21 00:48:08 300
原创 POJ 3694 Network
D - Network Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u SubmitStatusPracticePOJ 3694 Description A network administrator manages a large network. The network consis
2015-03-21 00:36:17 292
原创 HDU 4635 Strongly connected
G - Strongly connected Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatusPracticeHDU 4635 Description Give a simple directed graph with N nodes and M edges. P
2015-03-21 00:26:01 306
原创 HDU Caocao's Bridges
题意挺简单的但是有好多细节要处理好,就是让求所有割边最小权值 1)自环 2)如果地图根本不是一个联通图那么我们根本不需要炸,答案就是0 3)如果路上的侍卫是0,那么我们至少需要一个人去被炸, 此时答案是1 4)其他情况就正常来就行,求割边#include <iostream>#include <stdlib.h>#include <stdio.h>#include <string.h>
2015-03-19 00:04:57 493
原创 *POJ 3177 Redundant Paths**
POJ 3177 Redundant Paths 这道题是求一个变双联通分量,问你,最少加多少条边,可以使任意两个节点之间可以有两条路径 首先我们要知道,通过联通分量缩点以后我们可以形成一棵树,那么树的叶子节点数为cnt, (cnt+1)/2 便是答案, 然后就是Trajan求割边了,#include <iostream>#include <stdlib.h>#incl
2015-03-18 23:58:04 319
原创 Is It A Tree?
#include #include #include #include using namespace std;#define MAXN 111111int fa[MAXN];int node[MAXN];bool flag = 1;int findfa( int x){ if(fa[x] == -1) return x; return fa[x] = fin
2015-03-17 00:39:32 333
原创 Connections in Galaxy War
合并时要注意要求#include #include #include #include #include #include using namespace std;#define MAXN 10001int fa[MAXN];int pow[MAXN];int a[22222], b[22222];int ans[22222];map, bool> vis;
2015-03-17 00:37:21 613
原创 A Bug's Life
#include #include #include #include using namespace std;#define MAXN 1000000int fa[MAXN];int rel[MAXN];int findfa(int x){ if(fa[x] == -1) return x; int tem = findfa(fa[x]); rel[
2015-03-17 00:36:16 303
原创 小希的迷宫
#include #include #include #include using namespace std;#define MAXN 100010int fa[MAXN];bool vis[MAXN];bool flag = 1;int findfa( int x){ if(fa[x] == -1) return x; return fa[x] = fin
2015-03-17 00:35:44 380
原创 Parity game
#include #include #include #include #include using namespace std;map fa;map rel;int findfa(int x){ if(fa[x] == 0) return x; int tem = findfa(fa[x]); rel[x] = (rel[x] + rel[fa[x]
2015-03-17 00:35:06 315
原创 Supermarket
#include #include #include #include #include using namespace std;#define MAXN 10010struct node{ int p, d;}list[MAXN];int fa[MAXN];bool cmp(node a, node b){ if(a.p != b.p) ret
2015-03-17 00:32:27 424
原创 True Liars
给出p1+p2个人,其中p1个是好人,p2个是坏人。然后有一些关系 ,a说b是好人(坏人).其中没有矛盾的,判断是否有唯一解判断哪些人是好人,哪些人是坏人。其中比较重要的是,好人总说真话,坏人总说假话。不需要判断矛盾。唯一解 那么如果一个人说另一个人是好人,那么如果这个人是好人,说明 对方确实是好人,如果这个是坏人,说明这句话是假的,对方也是坏人。如果一个人说另一个人是坏人,
2015-03-17 00:31:34 360
原创 食物链(并查集, 向量偏移)
- 食物链Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 1182Description动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动
2015-03-17 00:29:57 323
原创 How Many Answers Are Wrong
How Many Answers Are WrongTime Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uSubmit Status Practice HDU 3038DescriptionTT and FF are ... friends. Uh... v
2015-03-17 00:26:10 318
原创 How Many Tables
How Many TablesTime Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uSubmit Status Practice HDU 1213DescriptionToday is Ignatius' birthday. He invites a lot
2015-03-17 00:24:09 248
原创 The Suspects
B - The SuspectsTime Limit:1000MS Memory Limit:20000KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 1611DescriptionSevere acute respiratory syndrome (SARS), an
2015-03-17 00:23:04 244
原创 poj 2186
Popular CowsTime Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64uSubmit StatusDescriptionEvery cow's dream is to become the most popular cow
2015-03-16 22:52:24 274
原创 The Suspects 并差集
#include #include #include #include #include using namespace std;#define MAXN 30000 + 11int fa[MAXN];int num[MAXN];int findfa(int x){ if(fa[x] == -1) return x; return fa[x] =
2015-03-13 17:50:24 319
原创 Wireless Network(并差集)
#include #include #include #include #include #include using namespace std;#define MAXN 1111int fa[MAXN];int x[MAXN], y[MAXN];bool ok[MAXN];vector rel[MAXN];int n, d;bool getdis(int i, in
2015-03-13 17:49:16 295
iOS app 模拟器图片显示不全
2016-01-06
TA创建的收藏夹 TA关注的收藏夹
TA关注的人