2013
12-03

# Eddy’s picture

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?

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.

Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the points.

3
1.0 1.0
2.0 2.0
2.0 4.0

3.41

#include<cstdio>
#include<cmath>
#include<cstring>
#include<climits> //INT_MAX的头文件
#include<algorithm>
using namespace std;

#define MAXN 110
double map[MAXN][MAXN], lowcost[MAXN];
bool visit[MAXN];
double sum;

struct point
{
double x, y;
};
point dian[MAXN];

double fun(const point x, const point y)
{
return sqrt((y.y - x.y) * (y.y - x.y) + (y.x - x.x) * (y.x - x.x));
}

void prim(int end)
{
double temp;
int i, j, k;
sum = 0;
memset(visit, false, sizeof(visit));
for(i = 1; i <= end; ++i)
lowcost[i] = map[1][i];
visit[1] = true;
for(i = 1; i <= end; ++i)
{
temp =INT_MAX; //这里错了N久。。以后就这么用了。。。
for(j = 1; j <= end; ++j)
if(!visit[j] && temp > lowcost[j])
temp = lowcost[k = j];
if(temp == INT_MAX)
break;
visit[k] = true;
sum += temp;
for(j = 1; j <= end; ++j)
if(!visit[j] && lowcost[j] > map[k][j])
lowcost[j] = map[k][j];
}
}

int main()
{
int i, j, num, count;
double x, y;
while(scanf("%d", &num) != EOF)
{
count = 0;
for(i = 1; i < MAXN; ++i)
for(j = 1; j < MAXN; ++j)
map[i][j] = INT_MAX;
for(i = 1; i <= num; ++i)
{
count++;
scanf("%lf%lf", &dian[count].x, &dian[count].y);
}
for(i = 1; i <= count; ++i)
for(j = 1; j <= count; ++j)
{
if(j == i) continue;
map[i][j] = min(map[i][j], fun(dian[i], dian[j]));
}
prim(count);
printf("%.2lf\n", sum);
}
return 0;
}

1. 有两个重复的话结果是正确的，但解法不够严谨，后面重复的覆盖掉前面的，由于题目数据限制也比较严，所以能提交通过。已更新算法

2. Excellent Web-site! I required to ask if I might webpages and use a component of the net web website and use a number of factors for just about any faculty process. Please notify me through email regardless of whether that would be excellent. Many thanks

3. 我没看懂题目
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
我觉得第一个应该是5 6 -1 5 4 输出是19 5 4
第二个是7 0 6 -1 1 -6 7输出是14 7 7
不知道题目例子是怎么得出来的

4. 如果两个序列的最后字符不匹配（即X [M-1]！= Y [N-1]）
L（X [0 .. M-1]，Y [0 .. N-1]）= MAX（L（X [0 .. M-2]，Y [0 .. N-1]），L（X [0 .. M-1]，Y [0 .. N-1]）
这里写错了吧。