首页 > 代码库 > NOIP2001T4car的旅行计划
NOIP2001T4car的旅行计划
洛谷传送门
一看数据就是floyed(毕竟年代久远),然而建图不是那么好贱好建,只知道三个机场,需要判断斜边来求第4个机场坐标。
往后一些麻烦的建图。
最后floyed就好。
——代码
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 5 using namespace std; 6 7 int n, s, a, b; 8 int t, x[401][5], y[402][5], T[401]; 9 double map[401][401], ans; 10 11 inline int square(int ax) 12 { 13 return ax * ax; 14 } 15 16 inline int dis(int ax, int ay, int bx, int by) 17 { 18 return square(ax - bx) + square(ay - by); 19 } 20 21 int main() 22 { 23 int i, j, k; 24 scanf("%d", &n); 25 while(n--) 26 { 27 scanf("%d %d %d %d", &s, &t, &a, &b); 28 for(i = 0; i < 4 * s; i++) 29 for(j = 0; j < 4 * s; j++) 30 map[i][j] = 1000000; 31 ans = 1000000; 32 for(i = 0; i < s; i++) 33 { 34 scanf("%d %d %d %d %d %d %d", &x[i][1], &y[i][1], &x[i][2], &y[i][2], &x[i][3], &y[i][3], &T[i]); 35 if(dis(x[i][1], y[i][1], x[i][2], y[i][2]) > dis(x[i][3], y[i][3], x[i][2], y[i][2]) 36 && dis(x[i][1], y[i][1], x[i][2], y[i][2]) > dis(x[i][3], y[i][3], x[i][1], y[i][1])) 37 { 38 x[i][4] = x[i][1] + x[i][2] - x[i][3]; 39 y[i][4] = y[i][1] + y[i][2] - y[i][3]; 40 } 41 else if(dis(x[i][1], y[i][1], x[i][3], y[i][3]) > dis(x[i][3], y[i][3], x[i][2], y[i][2]) 42 && dis(x[i][1], y[i][1], x[i][3], y[i][3]) > dis(x[i][2], y[i][2], x[i][1], y[i][1])) 43 { 44 x[i][4] = x[i][1] + x[i][3] - x[i][2]; 45 y[i][4] = y[i][1] + y[i][3] - y[i][2]; 46 } 47 else if(dis(x[i][2], y[i][2], x[i][3], y[i][3]) > dis(x[i][3], y[i][3], x[i][1], y[i][1]) 48 && dis(x[i][2], y[i][2], x[i][3], y[i][3]) > dis(x[i][2], y[i][2], x[i][1], y[i][1])) 49 { 50 x[i][4] = x[i][2] + x[i][3] - x[i][1]; 51 y[i][4] = y[i][2] + y[i][3] - y[i][1]; 52 } 53 map[4 * i][4 * i + 1] = map[4 * i + 1][4 * i] = sqrt(dis(x[i][1], y[i][1], x[i][2], y[i][2])) * T[i]; 54 map[4 * i][4 * i + 2] = map[4 * i + 2][4 * i] = sqrt(dis(x[i][1], y[i][1], x[i][3], y[i][3])) * T[i]; 55 map[4 * i][4 * i + 3] = map[4 * i + 3][4 * i] = sqrt(dis(x[i][1], y[i][1], x[i][4], y[i][4])) * T[i]; 56 map[4 * i + 1][4 * i + 2] = map[4 * i + 2][4 * i + 1] = sqrt(dis(x[i][2], y[i][2], x[i][3], y[i][3])) * T[i]; 57 map[4 * i + 1][4 * i + 3] = map[4 * i + 3][4 * i + 1] = sqrt(dis(x[i][2], y[i][2], x[i][4], y[i][4])) * T[i]; 58 map[4 * i + 2][4 * i + 3] = map[4 * i + 3][4 * i + 2] = sqrt(dis(x[i][3], y[i][3], x[i][4], y[i][4])) * T[i]; 59 for(j = 0; j < 4 * i; j++) 60 for(k = 4 * i; k < 4 * i + 4; k++) 61 map[k][j] = map[j][k] = sqrt(dis(x[j / 4][j % 4 + 1], y[j / 4][j % 4 + 1], x[k / 4][k % 4 + 1], y[k / 4][k % 4 + 1])) * t; 62 } 63 for(i = 0; i < 4 * s; i++) map[i][i] = 0; 64 for(k = 0; k < 4 * s; k++) 65 for(i = 0; i < 4 * s; i++) 66 for(j = 0; j < 4 * s; j++) 67 map[i][j] = min(map[i][j], map[i][k] + map[k][j]); 68 for(i = 4 * a - 4; i < 4 * a; i++) 69 for(j = 4 * b - 4; j < 4 * b; j++) 70 ans = min(ans, map[i][j]); 71 printf("%.1f\n", ans); 72 } 73 return 0; 74 }
NOIP2001T4car的旅行计划
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。