kruskal思想,排序后暴力枚举从任意边开始能够组成的最小生成树 #include <cstdio> #include <algorithm> using namespace std; const int maxn = 101; const int maxe = maxn * maxn / 2; struct edge{ int f,t,c; bool operator <(edge e2)const { return c<e2.c; } }e[maxe]; int…
http://poj.org/problem?id=3522 Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5666   Accepted: 2965 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is a…
Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7102   Accepted: 3761 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V …
Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 9546   Accepted: 5076 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V …
Slim Span Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3522 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V is a se…
http://poj.org/problem?id=3522 一开始做这个题的时候,以为复杂度最多是O(m)左右,然后一直不会.最后居然用了一个近似O(m^2)的62ms过了. 一开始想到排序,然后扫一个长度n - 1区间,要快速判定这个区间能否构成MST,一直都想不到优秀的算法,然后干脆暴力了. 两种方法,1.dfs,删边容易,标记一下就好,但是这是不行的,删边确实容易,但是dfs的时候多次访问无用的边,所以TLE了. 2.并查集,这个复杂度是O(n)的,能AC,但是我的思路还是有一点bug,…
题目链接:http://poj.org/problem?id=3522 Time Limit: 5000MS Memory Limit: 65536K Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V is a set of verti…
题目链接http://poj.org/problem?id=3522 kruskal+并查集,注意特殊情况比如1,0 .0,1.1,1 #include<cstdio> #include<iostream> #include<algorithm> #include<climits> using namespace std; #define MAXN 5005 struct edge{ int u,v,cost; }; int comp(const edge&…
Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19122   Accepted: 7366 Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for brick…
题意: 求出最小生成树中最大边与最小边差距的最小值. 分析: 排序,枚举最小边, 用最小边构造最小生成树, 没法构造了就退出 #include <stdio.h> #include <string.h> #include <iostream> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <se…
Help Me with the Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3510   Accepted: 2251 Description Your task is to read a picture of a chessboard position and print it in the chess notation. Input The input consists of an ASCII-art…
http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace std; int d[101][101];// dag ATTENTION int num[101];//the number of contracts int edge[101][101];// adjecent edge table int n;//always represent the maxnum of…
http://poj.org/problem?id=1860 #include <cstdio> //#include <queue> //#include <deque> #include <cstring> using namespace std; #define MAXM 202 #define MAXN 101 int n,m; int first[MAXN]; int next[MAXM]; int pto[MAXM]; double earn[M…
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; const int maxn = 21; bool vis[maxn][maxn]; char maz[maxn][maxn]; int n,m; const int dx[4] = {1,-1,0,0}; const int dy[4] = {0,0,1,-1}; int ans; bool in(int…
题目 http://poj.org/problem?id=1837 题意 单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物与重物之间,钩子与钩子之间彼此不同.忽略杠杆及重心的影响,有多少种方式使得全部重物都挂上钩子(某些钩子可能挂若干个重物)后杠杆平衡? 思路 由于状态比较小,即使n的五次方也足以承受,而且任意时刻杠杆的状态在[-15 * 25 * 20, 15 * 25 * 20]之间,所以可以直接穷举状态. 感想…
题目 http://poj.org/problem?id=2002 题意 已知平面内有1000个点,所有点的坐标量级小于20000,求这些点能组成多少个不同的正方形. 思路 如图,将坐标按照升序排列后,首先枚举p1,p2, 并判断p2是否在p1正下方或者左上角(因为每个正方形只有一条最右边或者是右下的边),按照下图计算p3,p4,判断p3,p4是否存在即可. 感想 排序时要注意和左上角这个信息相符,刚写完时用的是左下角,与升序排序不符合,会遗失部分正方形. 代码 #include <cstdio…
http://poj.org/problem?id=3126 搜索的时候注意 1:首位不能有0 2:可以暂时有没有出现在目标数中的数字 #include <cstdio> #include <cstring> #include <queue> using namespace std; const int maxn=1e4+5; const int inf=0x7fffffff; bool prim[maxn]; void judge(){ prim[2]=true; f…
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. Nowadays, Aoshu is getting more and more difficult. Here is a classic Aoshu problem: ABBDE __ ABCCC = BDBDE In the equation above, a letter stands for…
题意: 给你一个图,让你求这个图中所有生成树中满足题目条件的,这个条件是生成树中最长边与最短边的差值最小. 思路: 根据最小瓶颈生成树的定义:在一个有权值的无向图中,求一个生成树最大边的权值尽量小.首先以K算法做这道题,先给所有边排好序,然后我可以从小到大枚举每一条边作为我所求生成树的最短边(即第一次以最短边求最小生成树,第二次删除第一条边,以第二条边为最短边求最小生成树,第三次删除第一条边和第二条边,以第三边为最短边求最小生成树.)然后在这个过程中更新   MST(maxE- minE)就好了…
题意 求生成树的最长边与最短边的差值的最小值 题解 最小生成树保证每一条边最小,就只要枚举最小边开始,跑最小生成树,最后一个值便是最大值 在枚举最小边同时维护差值最小,不断更新最小值. C++代码 /** /*@author Victor /*language C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<…
http://acm.fzu.edu.cn/problem.php?pid=2150 注意这道题可以任选两个点作为起点,但是时间仍足以穷举两个点的所有可能 #include <cstdio> #include <cstring> #include <queue> using namespace std; const int maxn=11; const int inf=0x3fffffff; char maz[maxn][maxn]; int dp[maxn][maxn…
Description Students often have problems taking up seats. When two students want the same seat, a quarrel will probably begin. It will have very bad effect when such subjects occur on the BBS. So, we urgently need a seat-taking-up rule. After several…
先判断是不是连通图,不是就输出-1. 否则,把边排序,从最小的边开始枚举最小生成树里的最短边,对每个最短边用Kruskal算法找出最大边. 或者也可以不先判断连通图,而是在枚举之后如果ans还是INF,说明就没有,就输出-1. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath>…
题意:给一个图,找一棵生成树,其满足:最大权-最小权=最小.简单图,不一定连通,权值可能全相同. 思路:点数量不大.根据kruscal每次挑选的是最小权值的边,那么苗条度一定也是最小.但是生成树有多棵,苗条度自然也有多个,穷举下所有生成树,就知道了结果了.根据“只要起始边不同,生成树必定不同”来穷举起始边. 又发现一可能的坑!!我以为LONG_MAX就是int的正最大值,也就是2147483647=2^31-1,在我的机器上也许如此,在OJ上不一定了,用LONG_MAX转int会不同,得注意.…
题目链接:http://poj.org/problem?id=3522   Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7227   Accepted: 3831 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph…
题目链接:http://poj.org/problem?id=3522 Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7522   Accepted: 3988 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G…
Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7594   Accepted: 4029 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V …
Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 8633   Accepted: 4608 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V …
Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7462   Accepted: 3959 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V …
3887 - Slim SpanTime limit: 3.000 seconds Given an undirected weighted graph G <tex2html_verbatim_mark>, you should find one of spanning trees specified as follows. The graph G <tex2html_verbatim_mark>is an ordered pair (V, E) <tex2html_ver…