Eddy's picture
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11970    Accepted Submission(s): 6008
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

C/C++:

 #include <cmath>
#include <cstdio>
#include <climits>
#include <algorithm>
using namespace std; int n;
double my_map[][]; struct node
{
double a, b;
}P[]; double my_prim()
{
int my_pos = , my_book[] = {, };
double my_ans = 0.0, my_dis[] = {, INT_MAX};
for (int i = ; i <= n; ++ i)
my_dis[i] = my_map[i][my_pos]; for (int i = ; i < n; ++ i)
{
double my_temp = INT_MAX;
for (int j = ; j <= n; ++ j)
{
if (!my_book[j] && my_dis[j] < my_temp)
{
my_temp = my_dis[j];
my_pos = j;
}
}
my_ans += my_temp;
my_book[my_pos] = ;
for (int j = ; j <= n; ++ j)
{
if (!my_book[j] && my_dis[j] > my_map[j][my_pos])
my_dis[j] = my_map[j][my_pos];
}
}
return my_ans;
} int main()
{
/**
Date Input Initialize
*/
while (~scanf("%d", &n))
{
for (int i = ; i <= n; ++ i)
scanf("%lf%lf", &P[i].a, &P[i].b);
for (int i = ; i <= n; ++ i)
{
for (int j = i+; j <= n; ++ j)
{
double my_temp_a = (P[i].a - P[j].a) * (P[i].a - P[j].a);
double my_temp_b = (P[i].b - P[j].b) * (P[i].b - P[j].b);
double my_temp = sqrt(my_temp_a + my_temp_b);
my_map[i][j] = my_map[j][i] = my_temp;
}
}
printf("%.2lf\n", my_prim());
}
return ;
}

最新文章

  1. 正确地编写Objective-C中的便捷方法
  2. web前端知识体系总结
  3. 【PC网站前端架构探讨系列】关于中小型PC网站前端架构方案的讨论与实践
  4. oc 单例
  5. Javascript面向对象编程:构造函数的继承
  6. Discuz!NT 后台任意文件上传的源代码修补方法
  7. (转载)SQL中导入图片
  8. 淡淡de馨香---职业尊严
  9. hdu find the safest road
  10. 文本框文字垂直居中 CSS
  11. drag
  12. Arduino 开源库 u8glib2 之 图标显示【原创】
  13. Java学习之路- SQL注入
  14. Linux磁盘与文件系统管理笔记
  15. 野(wild)指针与悬空(dangling)指针
  16. spark application提交应用的两种方式
  17. C# Azure 用Webhook添加警报规则
  18. jsp 引用css/js文件返回html网页问题
  19. 基于ionic框架封装一个图片轮播指令的几点
  20. 华为笔试——C++最高分问题

热门文章

  1. [网络流 24 题] luoguP2763 试题库问题
  2. [Luogu3420][POI2005]SKA-Piggy Banks
  3. CSAPP: 位操作实现基本运算
  4. LeetCode刷题总结-递归篇
  5. Java匹马行天下之新手学习目录
  6. mysql数据库limit分页,排序操作
  7. ubuntu12.04 添加程序启动器
  8. 路由器配置深入浅出—路由器接口PPP协议封装及PAP和CHAP验证配置
  9. 学习笔记48_Memcache跟用户登录模块结合
  10. 前端与算法 leetcode 350. 两个数组的交集 II