BestCoder #74 B (div2)
来源:互联网 发布:sql怎么备份数据库 编辑:程序博客网 时间:2024/05/22 14:58
【题目来源】
题目传送门
【解题思路】
你可以选择分类讨论, 但是估计可能会写漏一些地方. 只要抽出新增边的端点作为关键点, 建立一个新图, 然后跑一遍floyd就好了. 复杂度大概O(62⋅m)O(6^2 \cdot m)O(62⋅m)
【AC代码】
#include <stdio.h>#include <string.h>#include <vector>#include <math.h>#include <stdlib.h>#include <iostream>#include <algorithm>using namespace std;#define CLE(a,b) memset(a,b,sizeof(a))#define MEC(a,b) memcpy(a,b,sizeof(a))#define PI acos(-1)#define ll long longconst ll MOD = 1000000007;void solve(){ int n,m; scanf("%d%d",&n,&m); int a[6]; for(int i=0; i<6; i++) scanf("%d",&a[i]); int maze[6][6]; for(int i=0; i<6; i++) { for(int j=0; j<6; j++) { maze[i][j] = abs(a[i]-a[j]); } } for(int j=0; j<3; j++) { int i = j*2; maze[i][i+1] = min(1,maze[i][i+1]); maze[i+1][i] = maze[i][i+1]; } for(int i=0; i<6; i++) for(int j=0; j<6; j++) for(int k=0; k<6; k++) if(maze[j][k]>maze[j][i]+maze[i][k]) maze[j][k] = maze[j][i]+maze[i][k]; ll ans = 0; for(ll i=1; i<=(ll)m; i++) { int u,v; scanf("%d%d",&u,&v); ll t = abs(u-v); for(int p=0; p<6; p++) { for(int q=0; q<6; q++) { ll tmp = abs(u-a[p])+abs(v-a[q])+maze[p][q]; t = min(tmp,t); } } ans = (ans+(i*t)%MOD)%MOD; } printf("%I64d\n",ans);}int main(){// ios::sync_with_stdio(0);// cin.tie(0); int T; scanf("%d",&T); while(T--) { solve(); } return 0;}
1 0
- BestCoder #74 B (div2)
- BestCoder Round #77 (div2) B
- HDU 5655 5656 ,Bestcoder #78 div2 A B
- BestCoder #74 A (div2) LCP Aarry
- bestcoder #11div2
- bestcoder #50 div2
- Bestcoder #54 div2
- Bestcoder Round#69 div2
- bestcoder round 71 div2
- Bestcoder Round 72# div2
- bestcoder #79 div2 A
- BestCoder Round #60 div2 A B C HDU 5504 5505 5506
- HDU 5560 5561 5562 5563 (Bestcoder#77 div2 A B C D)
- BestCoder Round #77 (div2) C
- hdu_5671_Matrix(BestCoder Round #81 (div2))
- hdu_5672_Strings BestCoder Round #81 (div2)
- Bestcoder Div2 #77 A So easy
- hdu 5652 bestcoder 77 div2 2
- 认识数据库系统
- UITableView性能优化
- IOS多线程 pThread NSThread 线程安全 个人笔记(一)
- VBA中将数字列转换成字母的方法
- 密码破解,N位随机序列数的生成
- BestCoder #74 B (div2)
- Linux下删除已创建用户
- 敏感词汇过滤DFA算法
- js、css的动态引入
- vba将列名的字母转为数字
- 网易2016研发题 [编程题] 小易的升级之路
- linux 学习记录
- setjmp()、longjmp() Linux Exception Handling/Error Handling、no-local goto
- 如何用Editplus编译运行Java