Outlets
Outlets
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2504 Accepted Submission(s): 1160
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.
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.
#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的更多相关文章
- HDOJ(HDU) 2304 Electrical Outlets(求和、、)
Problem Description Roy has just moved into a new apartment. Well, actually the apartment itself is ...
- hdu2304Electrical Outlets
Problem Description Roy has just moved into a new apartment. Well, actually the apartment itself is ...
- hdu 4463 Outlets(最小生成树)
Outlets Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submi ...
- HDU 4463 Outlets(最小生成树给坐标)
Problem Description In China, foreign brand commodities are often much more expensive than abroad. T ...
- Outlets 和Referencing Outlets的区别
转自:http://blog.sina.com.cn/s/blog_4431c7610100sypy.html 我的理解就是连接与被连接的关系吧 Outlets里面显示的是你的属性, 以及连接着的目标 ...
- zoj 2807 Electrical Outlets
Electrical Outlets Time Limit: 2 Seconds Memory Limit: 65536 KB Roy has just moved into a new a ...
- HDU—4463 Outlets 最小生成树
In China, foreign brand commodities are often much more expensive than abroad. The main reason is th ...
- POJ 2636:Electrical Outlets
Electrical Outlets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9597 Accepted: 718 ...
- [Angular] Auxiliary named router outlets
Define a auxilliary router: export const ROUTES: Routes = [ { path: 'folder/:name', component: MailF ...
随机推荐
- pycharm5.0.4简易使用说明
前言:学习自动化,需要使用pycharm,以下是简易使用说明 1.注册破解 2.行号和背景色 3.打断点 1.注册破解 打开pycharm5.0.4,点击菜单栏的help->register.. ...
- Delphi 快速读取TXT 指定行的数据
http://blog.csdn.net/MichaelJScofield/article/details/41869785 Delphi 快速读取TXT 指定行的数据 分类:Delphi个人挫品 ( ...
- Kubernetes tutorial - K8S 官方入门教程 中文翻译
官方教程,共 6 个小节.每一小节的第一部分是知识讲解,第二部分是在线测试环境的入口. kubectl 的命令手册 原文地址 1 创建集群 1.1 使用 Minikube 创建集群 Kubernete ...
- 简单入门爬斗鱼颜值区妹子照片 v1.1
这是个比较简单的入门爬虫.基于python3. urllib,urllib2,python3中用urllib.request代替,使用方法基本一致. #python3 import urllib.re ...
- Git011--分支管理策略
Git--分支管理策略 一.分支管理策略 通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,G ...
- 《JAVA设计模式》之策略模式(Strategy)
在阎宏博士的<JAVA与模式>一书中开头是这样描述策略(Strategy)模式的: 策略模式属于对象的行为模式.其用意是针对一组算法,将每一个算法封装到具有共同接口的独立的类中,从而使得它 ...
- js 为false的几种情况
1: false 2: null 3:undefined 4:"" 空字符串 5:0 6:NaN 如果你的if条件里面会出现 0 或者"",那么这种肯定是为假的 ...
- ‘’‘安装PyMouse,个人日志'''
管理员启动CMD 1.直接pip install pymouse,成功安装, 2.安装PyHook: https://www.lfd.uci.edu/~gohlke/pythonlibs/ (向下滑动 ...
- ADC(简易的DMA传输)的认识
ADC(简易的DMA传输)的认识 首先看到是ADC的特性 1.ADC的12位分辨率.不能直接测量负电压,然后是最小量程化单位是LSB=Vref+/212 2.单次和转换模式的使用 3. 从通道0到通道 ...
- 使用网易云web 版外部链接
右击打开控制台,找到音乐列表 ——> 点开详情 -------> 生成外部链接器 ,如: outchain/0/3073492173 ,这是每一个音乐的编号. 然后拼接上它的官网域名 ...