POJ-1258 Agri-Net---MST裸题Prim】的更多相关文章

给出一个n*m的图,其中m是人,H是房子,.是空地,满足人的个数等于房子数. 现在让每个人都选择一个房子住,每个人只能住一间,每一间只能住一个人. 每个人可以向4个方向移动,每移动一步需要1$,问所有人移动到房子里的最少花费. 其中,n,m<=100,最多有100个人. 最小给用流裸题. 建立一个超级源点,跟每一个房子连一条边,容量为1,花费为0 每一个人与超级汇点连一条边,容量为1,花费为0 一个房子与每一个人建一条边,房子指向人,容量为1,花费用2者的距离(不是直线距离) 然后跑最小费用流算…
题目链接: https://vjudge.net/problem/POJ-1258 题目大意: 求MST 思路: 由于给的是邻接矩阵,直接prim算法 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<map…
题目:http://poj.org/problem?id=1201 差分约束裸套路:前缀和 本题可以不把源点向每个点连一条0的边,可以直接把0点作为源点.这样会快许多! 可能是因为 i-1 向 i 都连着一条0的边. 别忘了约束条件不仅有s[ i ] - s[ i-1 ] >= 0,还有s[ i ] - s[ i - 1] <= 1! 别忘了s的范围不是n而是mx! #include<iostream> #include<cstdio> #include<cstr…
很裸,左点阵n,右点阵m 问最大匹配是否为n #include <cstdio> #include <cstring> #include <vector> using namespace std; vector <int> edge[103]; int pre[303]; bool vis[303]; int n, m; bool dfs(int u) { for(int i = 0; i < (int)edge[u].size(); i++) { i…
http://poj.org/problem?id=2407 题意:多组数据,每次输入一个数 ,求这个数的欧拉函数 int euler_phi(int n){//单个欧拉函数 int m=(int)sqrt(n+0.5); int ans=n; ;i<=m;i++)){ ans=ans/i*(i-); )n/=i; } )ans=ans/n*(n-); } 单个欧拉函数 int phi[maxn]; void phi_table(int n){//函数表 ;i<=n;i++)phi[i]=;…
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book: Tout avait Pair normal, mais tout s’affirmait faux. Tout avait Fair normal,…
Description You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect pairs of points. For each possible route between…
首先来介绍一下我们需求:给你n个数,多次问你某个区间内的第k小是哪个数 主席树: 主席树的全名应该是 函数式版本的线段树.加上附带的一堆 technology.. ..总之由于原名字太长了,而且 “主席” 两个字念起来冷艳高贵,以后全部称之为主席树好了.. 主席树的主体是线段树,准确的说,是很多棵线段树,存的是一段数字区间出现次数(所以要先离散化可能出现的数字).举个例子,假设我每次都要求整个序列内的第 k 小,那么对整个序列构造一个线段树,然后在线段树上不断找第 k 小在当前数字区间的左半部分…
POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> const int MAXN=101; const int INF=100000+10; int map[MAXN][MAXN]; int dis[MAXN]; int n; void prim() { bool vis[MAXN]={0}; for(int i=0;i<=n;i++) dis[i]…
1.HDU  1102  Constructing Roads    最小生成树 2.总结: 题意:修路,裸题 (1)kruskal //kruskal #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define max(a,b) a>b?a:b using na…