【HDU1162】Eddy's picture(MST基础题)
很基础的点坐标MST,一不留神就AC了, - - !!
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <limits.h> #define typec double
using namespace std; const int inf = 0xffff;
const int V = ;
int vis[V];
typec lowc[V], Map[V][V], point[V][]; typec prim (typec cost[][V], int n) {
int i, j, p;
typec minc, res = ;
memset(vis, , sizeof(vis));
vis[] = ;
for (i = ; i < n; ++ i) lowc[i] = cost[][i];
for (i = ; i < n; ++ i) {
minc = inf;
p = -;
for (j = ; j < n; ++ j) {
if ( == vis[j] && minc > lowc[j]) {
minc = lowc[j];
p = j;
}
}
if (inf == minc) return -;
res += minc;
vis[p] = ;
for (j = ; j < n; ++ j) {
if ( == vis[j] && lowc[j] > cost[p][j]) {
lowc[j] = cost[p][j];
}
}
}
return res;
} double cal_dis (double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
} int main () {
int n;
while (~scanf("%d", &n)) { for (int i = ; i < n; ++ i) {
scanf("%lf %lf", &point[i][], &point[i][]);
} for (int i = ; i < V; ++ i) {
for (int j = ; j < V; ++ j) {
if (i == j) Map[i][j] = ;
else Map[i][j] = inf;
}
} for (int i = ; i < n; ++ i) {
for (int j = i + ; j < n; ++ j) {
Map[i][j] = Map[j][i] =
cal_dis(point[i][], point[i][], point[j][], point[j][]);
}
} //cout << prim(Map, n) << endl;
printf("%.2lf\n", prim(Map, n));
}
return ;
}
【HDU1162】Eddy's picture(MST基础题)的更多相关文章
- hdu1162 Eddy's picture 基础最小生成树
#include <cstdio> #include <cmath> #include <cstring> #include <algorithm> # ...
- 【HDU1301】Jungle Roads(MST基础题)
爽爆.史上个人最快MST的记录7分40s..一次A. #include <iostream> #include <cstring> #include <cstdlib&g ...
- 【HDU1879】继续畅通工程(MST基础题)
真心大水题...不多说. #include <iostream> #include <cstring> #include <cstdlib> #include &l ...
- 【HDU1233】还是畅通工程(MST基础题)
无坑,裸题.直接敲就恩那个AC. #include <iostream> #include <cstring> #include <cstdio> #include ...
- 【HDU1102】Constructing Roads(MST基础题)
最小生成树水题.prim一次AC #include <iostream> #include <cstring> #include <cstdlib> #includ ...
- 【HDU3371】Connect the Cities(MST基础题)
注意输入的数据分别是做什么的就好.还有,以下代码用C++交可以过,而且是500+ms,但是用g++就会TLE,很奇怪. #include <iostream> #include <c ...
- 【HDU1875】畅通工程再续(MST基础题)
更改成实形数即可.第一次敲完直接交,CE了一次.晕. #include <iostream> #include <cstring> #include <cstdio> ...
- 【HDU2122】Ice_cream’s world III(MST基础题)
2坑,3次WA. 1.判断重边取小.2.自边舍去. (个人因为vis数组忘记初始化,WA了3次,晕死!!) #include <iostream> #include <cstring ...
- HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- Java 四大域对象总结
一.ServletContext 1.生命周期:当Web应用被加载进容器时创建代表整个web应用的ServletContext对象,当服务器关闭或Web应用被移除时,ServletContext对象跟 ...
- Android apk获取系统权限
Android在apk内部,即通过java代码来进行修改系统文件或者修改系统设置等等,这样需要获取系统权限. 通过直接配置apk运行在System进程内 1. 在应用程序的AndroidManifes ...
- maven编写主代码与测试代码
3.2 编写主代码 项目主代码和测试代码不同,项目的主代码会被打包到最终的构件中(比如jar),而测试代码只在运行测试时用到,不会被打包.默认情况下,Maven假设项目主代码位于src/main/ja ...
- [Javascript] Call Stack
Every time when a function run it will be push into the call stack and put on the top, you can thin ...
- 关闭归档提示:ORA-38774: cannot disable media recovery - flashback database is enabled
SQL> select * from v$version; Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit P ...
- Mybatis 插入操作时获取主键 (Oracle 触发器与SEQ)
1.通过Oracle序列 -- Create sequence create sequence SEQ_DW_EWSYSTEM minvalue 1 maxvalue 9999999999999999 ...
- roleManager 元素(ASP.NET 设置架构),我是因为SSL弱密码(转)
为角色管理配置应用程序. 此元素是 .NET Framework 2.0 版中的新元素. configuration 元素(常规设置架构) system.web 元素(ASP.NET 设置架构) ...
- Silverlight 设置颜色
透明色:00ff00ff //设置柱状图的颜色 ColorSet cs = new ColorSet(); cs.Id = "co ...
- 由MyEclipse内存不足谈谈JVM内存设置
转自:http://www.javatang.com/archives/2007/12/03/1653250.html 如果没有进行设置的话,在使用MyEclipse的经常出现如下图所示内存不足的提示 ...
- NSSet使用小结
http://blog.csdn.net/ms2146/article/details/8657011