codevs 1041

又到暑假了,住在城市A的Car想和朋友一起去城市B旅游。她知道每个城市都有四个飞机场,分别位于一个矩形的四个顶点上,同一个城市中两个机场之间有一条笔直的高速铁路,第I个城市中高速铁路了的单位里程价格为Ti,任意两个不同城市的机场之间均有航线,所有航线单位里程的价格均为t。

那么Car应如何安排到城市B的路线才能尽可能的节省花费呢?她发现这并不是一个简单的问题,于是她来向你请教。 任务 找出一条从城市A到B的旅游路线,出发和到达城市中的机场可以任意选取,要求总的花费最少。

输入描述                 Input Description

第一行为一个正整数n(0<=n<=10),表示有n组测试数据。 每组的第一行有四个正整数s,t,A,B。 S(0<S<=100)表示城市的个数,t表示飞机单位里程的价格,A,B分别为城市A,B的序号,(1<=A,B<=S)。 接下来有S行,其中第I行均有7个正整数xi1,yi1,xi2,yi2,xi3,yi3,Ti,这当中的(xi1,yi1),(xi2,yi2),(xi3,yi3)分别是第I个城市中任意三个机场的坐标,T I为第I个城市高速铁路单位里程的价格。

                输出描述                 Output Description              

共有n行,每行一个数据对应测试数据。

                样例输入                 Sample Input              

1 3 10 1 3 1 1 1 3 3 1 30 2 5 7 4 5 2 1 8 6 8 8 11 6 3

样例输出                 Sample Output              

47.5

#include<iostream>

#include<cstring>

#include<cstdio>

#include<cmath>

#define inf 0x1f1f1f1f

using namespace std;

double an[110][4][2];

double tn[110];

double t;

int s,A,B;

struct Edge

{

int c,d,next;

double w;

}edge[100000];

int head[10000][4],e;

void erase()

{

memset(head,-1,sizeof(head));

e = 0;

}

void increase(int a,int b,int c,int d,double w)

{

edge[e].c = c;

edge[e].d = d;

edge[e].w = w;

edge[e].next = head[a][b];

head[a][b] = e++;

}

void fq(int i)

{

double a = an[i][0][0],b = an[i][0][1],c = an[i][1][0],d = an[i][1][1],e = an[i][2][0],f = an[i][2][1];

double l11,l12,l21,l22;

l11 = c-a,l12 = d-b;

l21 = e-a,l22 = f-b;

if(l11*l21+l12*l22 == 0)

{

an[i][3][0] = c+l21;

an[i][3][1] = d+l22;

}

l11 = a-c,l12 = b-d;

l21 = e-c,l22 = f-d;

if(l11*l21+l12*l22 == 0)

{

an[i][3][0] = a+l21;

an[i][3][1] = b+l22;

}

l11 = a-e,l12 = b-f;

l21 = c-e,l22 = d-f;

if(l11*l21+l12*l22 == 0)

{

an[i][3][0] = a+l21;

an[i][3][1] = b+l22;

}

}

double fl(int a,int b,int c,int d)

{

return sqrt((an[a][b][0]-an[c][d][0])*(an[a][b][0]-an[c][d][0])+(an[a][b][1]-an[c][d][1])*(an[a][b][1]-an[c][d][1]));

}

double dis[110][4];

int q[100000][2],l,r;

bool inque[110][4];

void spfa(int a,int b)

{

int i,j;

for(i = 0;i<110;i++)

for(j = 0;j<4;j++)

dis[i][j] = 10000000000;

l = r = 0;

memset(inque,0,sizeof(inque));

dis[a][b] = 0;

q[r][0] = a,q[r++][1] = b;

inque[a][b] = 1;

while(l!=r)

{

int x = q[l][0],y = q[l++][1];

if(l == 100000) l = 0;

for(int t = head[x][y];t!=-1;t = edge[t].next)

{

double w = edge[t].w;

int xx = edge[t].c,yy = edge[t].d;

if(dis[xx][yy]>dis[x][y]+w)

{

dis[xx][yy] = dis[x][y]+w;

if(!inque[xx][yy])

{

inque[xx][yy] = 1;

q[r][0] = xx,q[r++][1] = yy;

if(r==100000)r = 0;

}

}

}

inque[x][y] = 0;

}

}

int main()

{

int z,i,j,k,ii,jj,kk;

cin>>z;

while(z--)

{

erase();

cin>>s>>t>>A>>B;

for(i = 1;i<=s;i++)

{

for(j = 0;j<3;j++)

{

cin>>an[i][j][0]>>an[i][j][1];

}

cin>>tn[i];

fq(i);

for(j = 0;j<4;j++)

{

for(k = j+1;k<4;k++)

{

double l = fl(i,j,i,k);

double w = l*tn[i];

increase(i,j,i,k,w);

increase(i,k,i,j,w);

}

}

}

for(i = 1;i<=s;i++)

{

for(j = i+1;j<=s;j++)

{

for(ii = 0;ii<4;ii++)

{

for(jj = 0;jj<4;jj++)

{

double l = fl(i,ii,j,jj);

double w = l*t;

increase(i,ii,j,jj,w);

increase(j,jj,i,ii,w);

}

}

}

}

double mi = 10000000000;

for(i = 0;i<4;i++)

{

spfa(A,i);

for(j = 0;j<4;j++)

{

if(mi>dis[B][j]) mi = dis[B][j];

}

}

printf("%.1lf\n",mi);

}

return 0;

}

codevs1041的更多相关文章

随机推荐

  1. apache的keepalive和keepalivetimeout

    在APACHE的httpd.conf中,KeepAlive指的是保持连接活跃,类似于Mysql的永久连接.换一句话说,如果将KeepAlive设置为On,那么来自同一客户端的请求就不需要再一次连接,避 ...

  2. Web App 聊天样式

    意见反馈: @using CommonDB.EF @model IEnumerable<Pub_ChatLog> @{ ViewBag.Title = "意见反馈"; ...

  3. for循环删除集合陷阱

    首先看下面的代码: import java.util.LinkedList;import java.util.List; public class DeleteCollection {         ...

  4. Unique Binary Search Trees In JAVA

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  5. 2014年1月9日 Oracle 内存与结构

    Oracle启动时为启动一个实例 主要为 实例 SVG 数据库文件 其它文件 1.Oracle:  内存 进程  其他文件 1.1 SVG内存(Cache)  1.1.1 共享池(Shared Poo ...

  6. GoEasy实现web实时推送过程中的自动补发功能

    熟悉GoEasy推送的朋友都知道GoEasy推送实现web实时推送并且能够非常准确稳定地将信息推送到客户端.在后台功能中查看接收信息详情时,可有谁注意到有时候在发送记录里有一个红色的R标志?R又代表的 ...

  7. Java Calendar获取年、月、日、时间

    Java Calendar获取年.月.日.时间 Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00" ...

  8. illegal to have multiple occurrences of contentType with different values (old: text/html; charset=UTF-8, new: text/html; charset=utf-8)

    问题描述: 在a.jsp通过<%@ include file="b.jsp" %> 的方式引入b.jsp,但是报了标题的中的错误, 问题原因: 在a.jsp的头部: & ...

  9. mysql隔离级别的设置和检索

    001.设置方式: 001.在/etc/my.cnf配置文件中设置,这个格式一定要记清楚呀! transaction-isolation=READ-COMMITTED 这里要写在“-”号不是“_&qu ...

  10. Inno Setup GIF 显示插件 GIFCtrl (V2.1 版本)

    原文 http://restools.hanzify.org/article.asp?id=79  引用来自 test.iss ; -- test.iss --; restools; http://r ...