codevs1041
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个城市高速铁路单位里程的价格。
共有n行,每行一个数据对应测试数据。
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
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的更多相关文章
随机推荐
- EF MySQL 提示 Specified key was too long; max key length is 767 bytes错误
在用EF的CodeFirst操作MySql时,提示 Specified key was too long; max key length is 767 bytes错误,但数据库和表也建成功了.有高人知 ...
- SqlHelper 简单版
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- linux的find指令详解。
引用:http://os.51cto.com/art/200908/141411.htm http://www.oschina.net/translate/15-practical-linux-fin ...
- Mysql查询高速缓存区
为了提高查询速度,Mysql会维护一个内存区域(官方文档指出,大小至少41984B)对查询结果进行缓存,当查询时发现缓存区里有数据则直接返回结果而不用去执行sql语句. 查询命中的条件 每个缓存查询至 ...
- mysql数据备份和还原命令
mysql数据库备份和还原 备份MySQL数据库的命令 mysqldump -hhostname -uusername -ppassword databasename > backupfil ...
- 【Android类型SDK测试(二)】环境基础
(一)语言 Android使用的Java语言,所以要测试Android类型的SDK,Java的基础知识还是需要的. 另外,Android中有NDK类型的编程,需要知道C相关的知识. (二)环境准备 A ...
- $.each与$(data).each区别
在前端使用使用JQuery解析Json数据时,在遍历数组或者对象数据时,经常使用的函数为each.发现此函数有两种形式: $.each $(data).each 所达到的效果是一样的,使用方法的有一些 ...
- Wcf实现IServiceBehavior拓展机制
IServiceBehavior接口 描述:提供一种在整个服务内修改或插入自定义拓展机制: 命名空间: System.ServiceModel.Description程序集: System.Ser ...
- Repeated meta-data items
B.2 Generating your own meta-data using the annotation processor You can easily generate your own co ...
- Unix/Linux环境C编程入门教程(25) C/C++字符测试那些事儿
isalnum isalpha isascii iscntrl isdigit isgraph isislower isprint isspace ispunct isupper isxdigit介绍 ...