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. HTTP状态码搜集

    一.1xx消息 这一类型的状态码,代表请求已经接受,需要继续处理. 这类响应是临时响应,只包含状态行和某些可选的响应头信息,并以空行结束. 由于HTTP/1.0协议中没有定义任何1xx状态码,所以除非 ...

  2. Lowest Common Ancestor of a Binary Search Tree、Lowest Common Ancestor of a Binary Search Tree

    1.Lowest Common Ancestor of a Binary Search Tree Total Accepted: 42225 Total Submissions: 111243 Dif ...

  3. c++STL之sort排序

    排序算法为竞赛中最常用的算法之一,我们可以利用C++自带的库函数进行排序.                                                                ...

  4. (转+原)VC编译错误:uafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义

    参考网址:http://zhanyonhu.blog.163.com/blog/static/16186044201023094754832/ 1>uafxcw.lib(afxmem.obj) ...

  5. 使用SQLiteHelper创建数据库并插入数据

    参考<疯狂android讲义>8.4节P424 1.获取SQLiteDatabase实例有2种方法,一是直接new SQLiteDatabase(),另一种使用SQLiteHelper.一 ...

  6. 快速解决js开发下拉框中blur与click冲突

    在开发中我们会经常遇到blur和click冲突的情况.下面叙述了开发中常遇到的"下拉框"的问题,并提供了两种解决方案. 一.blur和click事件简述 blur事件:当元素失去焦 ...

  7. 向Oracle数据库中CLOB插入数据报错问题

    今天在项目中向数据库的CLOB属性插入一段篇文章(1000~2000)字就会报一个字符串过长的错误. 网上说用流来处理,没有这么做.这像是一个Bug,只要把插入的数据,默认扩充到2000以上就ok了. ...

  8. BottomSheetBehavior 之 java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior

    AndroidRuntime: FATAL EXCEPTION: main Process: me.chunsheng.uberdriver, PID: 13674 java.lang.Runtime ...

  9. 喷水装置(一)--nyoj题目6

    喷水装置(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为Ri的喷水装置,每个喷水装置的效果都会让以它为中 ...

  10. eclipse 软件的背景颜色、字体设置

    1.eclipse 背景色设置: Window->Preferences->General->Editors->Text Editors->Backgroud color ...