博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4849-Wow! Such City!(最短路)
阅读量:6892 次
发布时间:2019-06-27

本文共 2851 字,大约阅读时间需要 9 分钟。

Wow! Such City!

Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 824    Accepted Submission(s): 310


Problem Description
Doge, tired of being a popular image on internet, is considering moving to another city for a new way of life.
In his country there are N (2 ≤N≤ 1000) cities labeled 0 . . . N - 1. He is currently in city 0. Meanwhile, for each pair of cities, there exists a road connecting them, costing C
i,
j (a positive integer) for traveling from city i to city j. Please note that C
i,
j may not equal to C
j,
i for any given i ≠ j.
Doge is carefully examining the cities: in fact he will divide cities (his current city 0 is 
NOT included) into M (2 ≤ M ≤ 10
6) categories as follow: If the minimal cost from his current city (labeled 0) to the city i is Di, city i belongs to category numbered 
Di mod M.Doge wants to know the “minimal” category (a category with minimal number) which contains at least one city.
For example, for a country with 4 cities (labeled 0 . . . 3, note that city 0 is not considered), Doge wants to divide them into 3 categories. Suppose category 0 contains no city, category 1 contains city 2 and 3, while category 2 contains city 1, Doge consider category 1 as the minimal one.
Could you please help Doge solve this problem?

Note:
Ci,j is generated in the following way:
Given integers X0, X1, Y0, Y1, (1 ≤ X0, X1, Y0, Y1≤ 1234567), for k ≥ 2 we have
Xk  = (12345 + Xk-1 * 23456 + Xk-2 * 34567 + Xk-1 * Xk-2 * 45678)  mod  5837501
Yk  = (56789 + Yk-1 * 67890 + Yk-2 * 78901 + Yk-1 * Yk-2 * 89012)  mod  9860381
The for k ≥ 0 we have
Zk = (Xk * 90123 + Yk ) mod 8475871 + 1
Finally for 0 ≤ i, j ≤ N - 1 we have
Ci,j = Zi*n+j for i ≠ j
Ci,j = 0   for i = j

 

Input
There are several test cases. Please process till EOF.
For each test case, there is only one line containing 6 integers N,M,X
0,X
1,Y
0,Y
1.See the description for more details.
 

Output
For each test case, output a single line containing a single integer: the number of minimal category.
 

Sample Input
 
3 10 1 2 3 4 4 20 2 3 4 5
 

Sample Output
 
1 10
头一次遇到区域赛的最短路的题目。。

尽管不是纯最短路(只是也差点儿相同了。。)权值由递推公式(题目中已给出)生成,然后跑一遍dijkstra,起点为1,求dis[i]%m的最小值。权值注意超出int范围要用lld

#include 
#include
#include
#include
#include
#define inf 0x3f3f3f3f#define ll long longusing namespace std;ll dis[1010],v[1010];ll map[1010][1010];int x0,x1,y0,y1,n,m;void dijkstra(){ int minx,k=0; for(int i=0; i<=n; i++) { dis[i]=map[0][i];; v[i]=0; } dis[0]=0; for(int j=0; j
dis[i]) { minx=dis[i]; k=i; } } v[k]=1; for(int i=0; i
dis[k]+map[k][i]) { dis[i]=dis[k]+map[k][i]; } } } return ;}ll xx[1002000],yy[1002000],zz[1002000];int main(){ while(scanf("%d%d%d%d%d%d",&n,&m,&x0,&x1,&y0,&y1)!=EOF) { for(int i=0; i

转载地址:http://ynhbl.baihongyu.com/

你可能感兴趣的文章
让你充满魅力的10大说话技巧
查看>>
我的友情链接
查看>>
MySQL学习笔记(一):shell脚本安装配置mysql
查看>>
Web程序运行原理
查看>>
RSF 分布式 RPC 服务信息的暴露
查看>>
apache日志切割
查看>>
How many file permissions are possible running ...
查看>>
Java对象的大小
查看>>
一、Docker之旅
查看>>
Java8新特性使用记录
查看>>
Java8新特性使用记录
查看>>
关于从下一页返回不要回到当前页的解决办法
查看>>
Linux开放端口
查看>>
java线程池的简单描述
查看>>
‘撤消或允许’重载
查看>>
TensorFlow人工智能引擎入门教程之十 最强网络 RSNN深度残差网络 平均准确率96-99%...
查看>>
关于访问Android项目中assets中的资源
查看>>
大家来解一解小学生题目......
查看>>
CentOS 6.4 & 6.5下DRBD的安装配置
查看>>
wp-setting.php文件详解
查看>>