HDU 1162 Prim
2015-01-26 21:55
316 查看
Eddy's picture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7287 Accepted Submission(s): 3689
Problem Description
Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result it can be imagined, the friends
are not interested in his picture.Eddy feels very puzzled,in order to change all friends 's view to his technical of painting pictures ,so Eddy creates a problem for the his friends of you.
Problem descriptions as follows: Given you some coordinates pionts on a drawing paper, every point links with the ink with the straight line, causes all points finally to link in the same place. How many distants does your duty discover the shortest length
which the ink draws?
Input
The first line contains 0 < n <= 100, the number of point. For each point, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the point.
Input contains multiple test cases. Process to the end of file.
Output
Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the points.
Sample Input
3 1.0 1.0 2.0 2.0 2.0 4.0
Sample Output
3.41
Author
eddy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7287 Accepted Submission(s): 3689
Problem Description
Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result it can be imagined, the friends
are not interested in his picture.Eddy feels very puzzled,in order to change all friends 's view to his technical of painting pictures ,so Eddy creates a problem for the his friends of you.
Problem descriptions as follows: Given you some coordinates pionts on a drawing paper, every point links with the ink with the straight line, causes all points finally to link in the same place. How many distants does your duty discover the shortest length
which the ink draws?
Input
The first line contains 0 < n <= 100, the number of point. For each point, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the point.
Input contains multiple test cases. Process to the end of file.
Output
Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the points.
Sample Input
3 1.0 1.0 2.0 2.0 2.0 4.0
Sample Output
3.41
Author
eddy
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int inf=0x3fffffff; double cost[107][107]; double ans; int n; struct node { double x,y; }; node e[10007]; bool used[107]; double dis[107]; void prim() { for(int i=1;i<=n;i++) { dis[i]=inf; used[i]=0; } dis[1]=0; while(1){ int v=-1; for(int i=1;i<=n;i++) { if(!used[i]&&(v==-1||dis[i]<dis[v])) v=i; } if(v==-1) break; used[v]=1; for(int i=1;i<=n;i++) { if(!used[i]) dis[i]=min(dis[i],cost[v][i]); } } // for(int i=1;i<=n;i++) // printf("%.2lf ",dis[i]); } int main() { //freopen("in.txt","r",stdin); while(~scanf("%d",&n)){ memset(e,0,sizeof(e)); for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) if(j==i) cost[i][j]=0; else cost[i][j]=inf; for(int i=1;i<=n;i++) scanf("%lf%lf",&e[i].x,&e[i].y); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { cost[i][j]=cost[j][i]=sqrt((e[i].x-e[j].x)*(e[i].x-e[j].x)+(e[i].y-e[j].y)*(e[i].y-e[j].y)); } prim(); ans=inf; double sum=0; for(int i=1;i<=n;i++) { sum+=dis[i]; } printf("%.2lf\n",sum); } return 0; }
相关文章推荐
- hdu 1162 prim模板
- hdu1162----------- prim模板
- hdu 1162 Eddy's picture(最小生成树,prim)
- HDU 1162 Eddy's picture(最小生成树-Prim)
- hdu 1162 Eddy's picture(Prim)
- hdu 1162 裸最下生成树 prim
- hdu 1162 Eddy's picture(最小生成树prim)
- HDU 1162 Prim
- hdu 1162 Prim
- HDU1162(prim)
- HDU1162 Eddy's picture【Prim】
- hdu1162 Eddy's picture(prim)
- hdu1162 Eddy's picture 最小生成树 prim
- hdu1879 继续畅通工程 (最小生成树之prim 算法)
- HDU 3080 The plan of city rebuild(prim和kruskal)
- HDU-1102(prim求最小生成树)
- hdu 1875 畅通工程再续 【最小生成树-prim】
- hdu 1162 Eddy's picture
- HDU 1233 还是畅通工程 最小生成树 Prim模板的应用
- hdu 3371 Connect the Cities(prim)