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. jquery方法详解

    jquery方法详解 http://www.365mini.com/doc

  2. C#常用的内置委托

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  3. c#中的数据类型简介(委托)

    c#中的数据类型简介(委托) 什么是委托? 委托是一种类型,它封装了一类方法,这些方法具有相同的方法签名(signature).定义听起来有点拗口,首先可以确定委托是一种数据类型,那么什么是方法签名, ...

  4. CDZSC_2015寒假新人(1)——基础 f

    Description An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u i ...

  5. 为什么JavaScript函数中的参数前面不能加var

    首先这里是JavaScript的语法规则. 其次在调用function()函数的时候参数时外部传入的.在传入之前就已经被声明了.没必要在函数参数里声明. 如果想要在函数里用新的参数 function( ...

  6. css3渐变详解

    今天总结渐变的问题,渐变分为线性渐变.径向渐变.呼呼,废话少说, 线性渐变:background:linear-gradient(设置渐变形式,第一个颜色起点,中间颜色点 中间颜色的位置,结束点颜色) ...

  7. python核心编程-第三章-个人笔记

    1.语句和语法 (1)反斜杠"\"表示语句继续.python良好的编程习惯是一行最后不超过80个字符,一行字符过多时便须用到反斜杠换行继续该语句. PS:在使用小括号.中括号.大括 ...

  8. Oracle EBS-SQL (MRP-5):重起MRP Manager.sql

    UPDATE fnd_concurrent_processes SET process_status_code = 'K' WHERE process_status_code not in ('K', ...

  9. 从HCE的各种问题 讨论未来趋势

    为了能让NFC手机支持NFC支付,维萨公司和万事达公司宣布了对HCE的研发,并且将很快推出最新的HCE规范.从2012年末,我一直在关注关于HCE的相关信息,其原因是由于我们公司参与了名为Simply ...

  10. QT 小票打印

    原地址: http://www.cppblog.com/biao/archive/2009/09/08/95603.html QString htmlString = QString("&l ...