ZOJ - 3204 Connect them 最小生成树】的更多相关文章

Connect them ZOJ - 3204 You have n computers numbered from 1 to n and you want to connect them to make a small local area network (LAN). All connections are two-way (that is connecting computers i and j is the same as connecting computers j and i). T…
Connect them Time Limit: 1 Second      Memory Limit: 32768 KB You have n computers numbered from 1 to n and you want to connect them to make a small local area network (LAN). All connections are two-way (that is connecting computers iand j is the sam…
题意:裸最小生成树,主要是要按照字典序. 思路:模板 prim: #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define INF 0x7fffffff #define MAXN 128 bool vis[MAXN]; int lowu[MAXN];//记录起始边(已加入集合中的边) int lowc[MAX…
主要就是将最小生成树的边按字典序输出. 读取数据时,把较小的端点赋给u,较大的端点号赋值给v. 这里要用两次排序,写两个比较器: 第一次是将所有边从小到大排序,边权相同时按u从小到大,u相同时按v从小到大,用kruskal求出最小生成树. 第二次将求出的最小生成树的边在排序,这次只要按u.v从小到大排序即可. #include <algorithm> #include <cstring> #include <cstdio> using namespace std; in…
这道题目麻烦在输出的时候需要按照字典序输出,不过写了 Compare 函数还是比较简单的 因为是裸的 Kruscal ,所以就直接上代码了- Source Code : //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream> #include <cstring…
最小生成树,我用的是并查集+贪心的写法. #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; ; int c[maxn][maxn]; int father[maxn]; int flag[maxn]; struct abc{ int fei, a, b; }dt[maxn*maxn]; struct ans{ int a…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3367 题目大意: 让你求最小生成树,并且按照字典序输出哪些点连接.无解输出-1 这里的字典序定义为:(不翻译啦~,详见我的比较函数) A solution A is a line of p integers: a1, a2, ...ap. Another solution B different from A is a line of q integers: b1, b2,…
注意排序即可 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> using namespace std; #define for0n for(i=0;i<n;i++) #define for1n for(i=1;i<=n;i++) #define for0m fo…
Connect them Time Limit: 1 Second      Memory Limit:32768 KB You have n computers numbered from 1 ton and you want to connect them to make a small local area network (LAN). All connections are two-way (that is connecting computersi andj is the same a…
QS Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 1586 Appoint description:  System Crawler  (2015-05-31) Description Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3367 题目就是简单的最小生成树的模板的应用,不过最小生成树可能不唯一,答案要求输出字典序最小 代码: #include<cstdlib> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace…
题目链接: PKU:http://poj.org/problem?id=1861 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=542 Description Andrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the c…
Traveler Nobita Time Limit: 2 Seconds      Memory Limit: 65536 KB One day, Nobita used a time machine and went back to 1000 AD. He found that there are N cities in the kingdom he lived. The cities are numbered from 0 toN - 1. Before 1000 AD., there a…
首先,贴上一个很好的讲解贴: http://www.wutianqi.com/?p=3012 HDOJ 1233 还是畅通工程 http://acm.hdu.edu.cn/showproblem.php?pid=1233 裸的Prim... #include<cstdio> #define MAXN 105 #define INF 0x3f3f3f3f int map[MAXN][MAXN]; int dist[MAXN]; int vis[MAXN]; int n,a,b,x,ans,tot…
题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Andrew is working as system administrator and is planning to establish a new network in his com…
主题链接:problemId=203" target="_blank">ZOJ 1203 Swordfish 旗鱼 Swordfish Time Limit: 2 Seconds      Memory Limit: 65536 KB There exists a world within our world A world beneath what we call cyberspace. A world protected by firewalls, password…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3371 984ms风险飘过~~~ /************************************************************************/ /* hdu Connect the Cities 最小生成树 题目大意:最小生成树,题目很长,题意很简单就是最小生成树.关键是构建图 */ /****************************************…
Connect the Cities Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9985    Accepted Submission(s): 2843 Problem Description In 2100, since the sea level rise, most of the cities disappear. Thou…
这个时间短 700多s #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; struct node{ int u; int v; int w; }que[100000]; int father[505]; bool cmp(struct node a,struct node b){ return a.w<b.w;…
题意:给出一组含m个点的无向图,再给出n个点,这n个点分别以一条边连接到这个无向图中的某个点.对于每个询问,求出3点连通的最小代价.有可能3个点是不能互通的.如图,最小代价就是红色的边的权之和. 思路:先对m个点的无向图进行求两两之间最短路径,用floyd.接下来对于每个询问,穷举m个点,求3个点分别到该点的距离之和,求最小即可. //#include <bits/stdc++.h> #include <iostream> #include <cstdio> #incl…
uvaoj 10397 - Connect the Campus Many new buildings are under construction on the campus of the University of Waterloo. The university has hired bricklayers, electricians, plumbers, and a computer programmer. A computer programmer? Yes, you have been…
地址:http://acm.hdu.edu.cn/showproblem.php?pid=3371 其实就是最小生成树,但是这其中有值得注意的地方:就是重边.题目没有告诉你两个城市之间只有一条路可走,所以两个城市之间可能有多条路可以走. 举例: 输入可以包含 1 2 3  // 1到2的成本为3   1 2 5  //1到2的成本为5      因此此时应选成本较低的路. 然后,已经连通的城市之间的连通成本为0. 这题用G++提交得到984ms的反馈,用C++提交则得到484ms的反馈. 很想知…
Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem E: QS Network In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunicate with each other via networks. If two QS want to get connected, they…
解题报告:有n个点,然后有m条可以添加的边,然后有一个k输入,表示一开始已经有k个集合的点,每个集合的点表示现在已经是连通的了. 还是用并查集加克鲁斯卡尔.只是在输入已经连通的集合的时候,通过并查集将该集合的点标记到一起,然后剩下的就可以当成是普通的最小生成树来做了题目代码如下: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cstd…
Escape Time II Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2966 Description In last winter, there was a big snow storm in South China. The electric system was damaged seriously. Lots of p…
QS Network Sunny Cup 2003 - Preliminary Round April 20th, 12:00 - 17:00 Problem E: QS Network In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunicate with each other via networks. If two QS want to get conne…
http://acm.hdu.edu.cn/showproblem.php?pid=3371 AC代码: /** /*@author Victor /* C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3371 题目不难 稍微注意一下 要把已经建好的城市之间的花费定义为0,在用普通Prim算法就可以了:我没有用克鲁斯卡尔算法(Kruskal's algorithm),因为这题数据比较大,而且要处理大量的数据使它为0,怕超时T^T..... #include<iostream> #include<cstdio> #include<algorithm> using namespa…
链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1586 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82831#problem/E In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunicate with each o…
Build The Electric System Time Limit: 2 Seconds      Memory Limit: 65536 KB In last winter, there was a big snow storm in South China. The electric system was damaged seriously. Lots of power lines were broken and lots of villages lost contact with t…