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. windows10上使用一个tomcat部署2个项目

    前言:目前想在本机部署2个项目,网上查了之后,写下本篇随笔 1.准备工作 2.操作方法 3.运行2个项目 1.准备工作 2个war包(一个jprss.war和一个jenkins.war) 1个tomc ...

  2. 用Delphi从内存流中判断图片格式[转]

    http://blog.163.com/tfn2008%40yeah/blog/static/110321319201222243214337/ 用Delphi从内存流中判断图片格式[转] 2012- ...

  3. 在windows上使用xdmcp登陆centos,红帽linux

    使用xdmcp协议可以方便的在远端登陆linux服务器,进行一些界面的操作. 修改服务器端配置. vi /etc/gdm/custom.conf 找到下面两个标签 [security] AllowRe ...

  4. note3

    awk awk “样式” 文件: 把符合样式的数据行显示出来.awk { 操作 } 文件: 对每一行都执行{}中的操作.awk " 样式 { 操作 }" 文件: 对符合样式的数据行 ...

  5. 排序算法五:随机化快速排序(Randomized quicksort)

    上一篇提到,快速排序的平均时间复杂度是O(nlgn),比其他相同时间复杂度的堆排序.归并排序都要快,但这是有前提的,就是假定要排序的序列是随机分布的,而不是有序的.实际上,对于已经排好的序列,如果用快 ...

  6. nmon内存分析

    可参考: MemTotal:显示当前服务器物理内存大小,本服务器有8063180 KB≍7874 MB左右. MemFree:显示当前服务器的空闲内存大小,本服务器有5052336 KB≍4934 M ...

  7. mysql中插入中文时显示乱码

    在插入mysql的时候参数是中文的时候显示的是???乱码,这个是由于没有配置字符编码引起的 只要在SqlMapconfig.xml文件中加上<property name="url&qu ...

  8. Spring之AOP简单demo

    1.加入JAR包.出了Spring自身的Jar包还要一些依赖的JAR包.不然会报ClassNotFound. Student.java package com.lubby.bean; import o ...

  9. while例子 求1到100的和

  10. 如何卸载不用的VDP

    1.首先删除VDP 2.登录AD的DNS当中,删除VDP对应的DNS解析 3.1登陆 https://vcenterip/mob 这个地址. 输入你的管理员账号密码. 3.2进入content链接. ...