当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4849:Wow! Such City!

题目描述
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 Ci,j (a positive integer) for traveling from city i to city j. Please note that Ci,j may not equal to Cj,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 ≤ 106) 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
输入解释
There are several test cases. Please process till EOF.
For each test case, there is only one line containing 6 integers N,M,X0,X1,Y0,Y1.See the description for more details.
输出解释
For each test case, output a single line containing a single integer: the number of minimal category.
输入样例
3 10 1 2 3 4
4 20 2 3 4 5
输出样例
1
10

For the first test case, we have


	   0	   1	   2	   3	   4	   5	   6	   7	   8
X	   1	   2	 185180	 788997	1483212	4659423	4123738	2178800	 219267
Y	   3	   4	1633196	7845564	2071599	4562697	3523912	317737	1167849
Z	 90127	 180251	1620338	2064506	 625135	5664774	5647950	8282552	4912390

the cost matrix C is
	         	   0	 180251	1620338
	                2064506	   0	5664774
	                5647950	8282552	   0

提示
So the minimal cost from city 0 to city 1 is 180251, while the distance to city 2 is 1620338.
Given M = 10, city 1 and city 2 belong to category 1 and 8 respectively.
Since only category 1 and 8 contain at least one city,
the minimal one of them, category 1, is the desired answer to Doge’s question.
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-4849

最后修改于 2020-10-25T23:17:25+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
15000/8000MS(Java/Others) 102400/102400K(Java/Others)