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 ...
随机推荐
- 015-Spring Boot 定制和优化内嵌的Tomcat
一.内嵌web容器 参看http://www.cnblogs.com/bjlhx/p/8372584.html 查看源码可知提供以下三种: 二.定制优化tomcat 2.1.配置文件配置 通过appl ...
- Jenkins+Git+Gitlab+Ansible实现持续集成自动化部署静态网站
环境准备 三台主机: 一台主机部署jenkins和作为ansible的管理主机 一台主机部署gitlab和ansible的节点1 一台主机为ansible的节点2 防火墙和apache服务关闭 第一步 ...
- (appium+python)UI自动化_02_appium启动手机app
前提:需先安装配置好appium+python自动化环境,已配置好环境的小伙伴可以参考以下步骤启动Android app,具体步骤如下: 一.USB连接手机 (1)手机USB连接电脑 (2)手机打开开 ...
- jmeter动态修改线程组参数
jmeter非gui模式修改线程属性进行性能测试 在使用JMeter进行性能测试自动化时,如果按照平常的非Gui模式就是脚本每次修改参数都需要在gui模式下修改保存之后,然后在非gui模式之后运行,这 ...
- LeetCode 129. Sum Root to Leaf Numbers 动态演示
树的数值为[0, 9], 每一条从根到叶子的路径都构成一个整数,(根的数字为首位),求所有构成的所有整数的和 深度优先搜索,通过一个参数累加整数 class Solution { public: vo ...
- css负边距布局
三行三列的布局 代码结构 <div class="container"> <ul> <li>1</li> <li>2&l ...
- 1、Laravel 环境配置及安装
一.开发工具及环境 PHPStorm + phpStudy 最新版 Composer 安装 https://www.phpcomposer.com/ 下载就可以,设置中国镜像 安装完成后 compos ...
- 如何在Python中使用Linux epoll
如何在Python中使用Linux epoll 内容 介绍 阻塞套接字编程示例 异步套接字和Linux epoll的好处 epoll的异步套接字编程示例 性能考量 源代码 介绍 从2.6版开始,Pyt ...
- Spring Security 01
环境搭建 maven依赖jar包 <!-- spring-security --> <dependency> <groupId>org.springframewor ...
- Oracle PL/SQL基础
1.下载sql developer数据库连接可视化工具 连接地址:点我下载 下载完成,安装有Java环境,解压即可运行,也可以在linux系统中运行.