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 ...
随机推荐
- 腾讯两大开源项目Tars、TSeer
6月25日,在LC3(LinuxCon + ContainerCon + CloudOpen)中国2018大会上,腾讯宣布其两大开源项目——RPC开发框架Tars.轻量化名字服务方案TSeer,加入L ...
- 2019/12/22 TZOJ
4986 Team Formation http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=498 ...
- Windows系统命令整理-Win10
硬件相关 显卡 显卡升级 - 我的电脑->属性->设备管理器->显示适配器->更新驱动程序 服务 telnet 安装:启用或关闭Windows 功能,勾选上“Telnet客户端 ...
- 关于eclipse中的maven插件问题
最近上课讲eclipse 中的maven插件 有一个坑确实比较坑,实际上就是一个配置的原因. 就是在eclipse中设置java 的buildpath的时候,一般不注意往往都设置成了jre的,这样的话 ...
- 转载 IDEA搭建maven项目详细步骤(解决没有src及其下面的文件)
转载自
- jvm 这我就能会了 擦
最近老有人问jvm,恕我直言,完蛋了,不会,慢慢学吧,开始第一个学习,后续补充,走起... 我看的他的https://www.cnblogs.com/dingyingsi/p/3760447.html ...
- noip2018考后反思之爆0
今年又被Han老师鞭尸了TAT noip普及组比齐同学考的都差,正在准备退役Orz 哎,算了,该放题解还是要放的:( 普及第一题我觉得没有放的必要还是放一下 Code: #include<ios ...
- 洛谷 P1972 [SDOI2009]HH的项链(树状数组,离线)
传送门 解题思路 因为是求区间的不同种类数,所以我们用树状数组(貌似并没有什么直接联系) (...表示到) 还是和原来一样,用s[i]来表示a[i-lowbit(i)]...a[i]的种类数. 因为有 ...
- [HDU 5293]Tree chain problem(树形dp+树链剖分)
[HDU 5293]Tree chain problem(树形dp+树链剖分) 题面 在一棵树中,给出若干条链和链的权值,求选取不相交的链使得权值和最大. 分析 考虑树形dp,dp[x]表示以x为子树 ...
- JS :Date日期格式化
Date.prototype.format = function (formatStr) { var date = this; /* 函数:填充0字符 参数:value-需要填充的字符串, lengt ...