Outlets

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2504    Accepted Submission(s): 1160

Problem Description
In
China, foreign brand commodities are often much more expensive than
abroad. The main reason is that we Chinese people tend to think foreign
things are better and we are willing to pay much for them. The typical
example is, on the United Airline flight, they give you Haagendazs ice
cream for free, but in China, you will pay $10 to buy just a little cup.
So
when we Chinese go abroad, one of our most favorite activities is
shopping in outlets. Some people buy tens of famous brand shoes and bags
one time. In Las Vegas, the existing outlets can't match the demand of
Chinese. So they want to build a new outlets in the desert. The new
outlets consists of many stores. All stores are connected by roads. They
want to minimize the total road length. The owner of the outlets just
hired a data mining expert, and the expert told him that Nike store and
Apple store must be directly connected by a road. Now please help him
figure out how to minimize the total road length under this condition. A
store can be considered as a point and a road is a line segment
connecting two stores.
 
Input
There
are several test cases. For each test case: The first line is an
integer N( 3 <= N <= 50) , meaning there are N stores in the
outlets. These N stores are numbered from 1 to N. The second line
contains two integers p and q, indicating that the No. p store is a Nike
store and the No. q store is an Apple store. Then N lines follow. The
i-th line describes the position of the i-th store. The store position
is represented by two integers x,y( -100<= x,y <= 100) , meaning
that the coordinate of the store is (x,y). These N stores are all
located at different place. The input ends by N = 0.
 
Output
For each test case, print the minimum total road length. The result should be rounded to 2 digits after decimal point.
 
Sample Input
4
2 3
0 0
1 0
0 -1
1 -1
 
0
 
Sample Output
3.41
 
Source
 
Recommend
题意:求最小生成树,p点和q点必须连着
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <queue>
#include <stack>
#include <vector>
#include <map> using namespace std; #define N 55
#define INF 0xfffffff
#define PI acos (-1.0)
#define EPS 1e-8
#define Lson rt<<1, l, tree[rt].mid ()
#define Rson rt<<1|1, tree[rt].mid () + 1, r struct node
{
int x, y;
} P[N]; int n, vis[N]; double maps[N][N], dist[N]; void init()
{
for(int i = ; i <= n; i++)
{
vis[i] = ;
for(int j = ; j <= n; j++)
maps[i][j] = maps[j][i] = INF;
maps[i][i] = ;
}
} int main()
{
int p, q; while(scanf("%d", &n), n)
{
init(); scanf("%d%d", &p, &q); for(int i = ; i <= n; i++)
scanf("%d%d", &P[i].x, &P[i].y); int x = abs(P[p].x-P[q].x);
int y = abs(P[p].y-P[q].y); double tmp = 1.0*sqrt(x*x+y*y); for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
int f = abs(P[i].x-P[j].x), g = abs(P[i].y-P[j].y); maps[i][j] = 1.0*sqrt(f*f+g*g);
maps[j][i] = maps[i][j];
}
} maps[p][q] = maps[q][p] = ; double ans = ; dist[] = ; for(int i = ; i <= n; i++)
dist[i] = maps[i][]; vis[] = ; for(int i = ; i < n; i++)
{
int index;
double Min = INF; // double Min, 不知道在这错多少回了
for(int j = ; j <= n; j++)
{
if(!vis[j] && dist[j] < Min)
Min = dist[j], index = j;
}
vis[index] = ;
ans += Min;
for(int j = ; j <= n; j++)
{
if(!vis[j] && dist[j] > maps[j][index])
dist[j] = maps[j][index];
}
}
printf("%.2f\n", ans+tmp);
}
return ;
}

Outlets的更多相关文章

  1. HDOJ(HDU) 2304 Electrical Outlets(求和、、)

    Problem Description Roy has just moved into a new apartment. Well, actually the apartment itself is ...

  2. hdu2304Electrical Outlets

    Problem Description Roy has just moved into a new apartment. Well, actually the apartment itself is ...

  3. hdu 4463 Outlets(最小生成树)

    Outlets Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submi ...

  4. HDU 4463 Outlets(最小生成树给坐标)

    Problem Description In China, foreign brand commodities are often much more expensive than abroad. T ...

  5. Outlets 和Referencing Outlets的区别

    转自:http://blog.sina.com.cn/s/blog_4431c7610100sypy.html 我的理解就是连接与被连接的关系吧 Outlets里面显示的是你的属性, 以及连接着的目标 ...

  6. zoj 2807 Electrical Outlets

    Electrical Outlets Time Limit: 2 Seconds      Memory Limit: 65536 KB Roy has just moved into a new a ...

  7. HDU—4463 Outlets 最小生成树

    In China, foreign brand commodities are often much more expensive than abroad. The main reason is th ...

  8. POJ 2636:Electrical Outlets

    Electrical Outlets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9597   Accepted: 718 ...

  9. [Angular] Auxiliary named router outlets

    Define a auxilliary router: export const ROUTES: Routes = [ { path: 'folder/:name', component: MailF ...

随机推荐

  1. 《图解设计模式》读书笔记4-1 Bridge模式

    目录 概念 代码 角色 类图 想法 概念 Bridge模式即桥接模式.顾名思义,这个模式的作用是将类的功能层次结构和类的实现层次结构连接起来. 功能层次结构 Something -SomethingG ...

  2. vue+element-ui国际化(i18n)

    1. 下载element-ui和vue-i18n: npm i element-ui --save   npm i vue-i18n –save 2.  创建一个  i18n 文件夹, 在main.j ...

  3. 【BASIS系列】SAP 设置系统timeout时间

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[BASIS系列]SAP 设置系统timeout ...

  4. SAP选择屏幕开发(二)(转)

    原文链接:https://blog.csdn.net/wtxhai/article/details/90698683 1.2.SAP屏幕框架的创建        SAP页面设计中的框架不但可以保证SA ...

  5. 实现自己的DiscoveryClient

    需要做的: DiscoveryClient能提供那些服务的服务名列表 返回指定服务对于的ServiceInstance列表 返回DiscoveryClient的顺序 返回HealthIndicator ...

  6. 洛谷 P3374 【模板】树状数组 1(单点加,区间和)

    题目链接 https://www.luogu.org/problemnew/show/P3374 树状数组 树状数组最基本的就是求区间和. 维护: 空间复杂度:O(n) 时间复杂度(区间和,单点修改) ...

  7. Day6----Python的pyinstall库的使用

    Python的pyinstaller库 pyinstaller的安装 介绍:pyinstaller是Python的第三方库,主要用于将Python代码打包成  可执行文件    ,以此达到就算没安装P ...

  8. /dev/random vs /dev/urandom

    If you want random data in a Linux/Unix type OS, the standard way to do so is to use /dev/random or ...

  9. P4126 [AHOI2009]最小割(网络流+tarjan)

    P4126 [AHOI2009]最小割 边$(x,y)$是可行流的条件: 1.满流:2.残量网络中$x,y$不连通 边$(x,y)$是必须流的条件: 1.满流:2.残量网络中$x,S$与$y,T$分别 ...

  10. go web编程——自定义路由设计

    本文主要讲解go语言web编程中自定义路由器的设计.在此之前需要先了解一下go语言web编程中路由与http服务的基本原理,可以参考笔者另一篇博文:go web编程——路由与http服务 . 我们已经 ...