HDU 4849 nyist省赛选拔题目
来源:互联网 发布:中国那个朝代最弱知乎 编辑:程序博客网 时间:2024/05/29 04:40
C - Wow! Such City!
HDU - 4849Wow! Such City!
Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Submission(s): 1740 Accepted Submission(s): 586
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 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
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
Input
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, there is only one line containing 6 integers N,M,X0,X1,Y0,Y1.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 44 20 2 3 4 5
Sample Output
110For the first test case, we have 0 1 2 3 4 5 6 7 8X 1 2 185180 7889971483212465942341237382178800 219267Y 3 4163319678455642071599456269735239123177371167849Z 90127 18025116203382064506 6251355664774564795082825524912390the cost matrix C is 0 1802511620338 2064506 05664774 56479508282552 0HintSo 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.
Source
2014西安全国邀请
0 0
- HDU 4849 nyist省赛选拔题目
- 省赛选拔
- 2015省赛选拔
- 2013省赛选拔
- 省赛选拔
- 西北工业大学省赛选拔!!!
- 选拔题目总结
- 省赛第二场选拔
- 省赛选拔第二场
- 省赛选拔第六场
- hpuacm 第一次省赛选拔
- NWPU省赛选拔2017
- 【hdu 2188】选拔志愿者
- acm省赛选拔组队赛经验谈
- 省赛选拔之愚人节专题
- XDU-2017省赛选拔第一场
- Java 大数的几道题目 nyist
- 第六届蓝桥杯大赛个人赛(软件类)校内选拔题目X^X=10
- bzoj1089: [SCOI2003]严格n元树
- 精通Oracle SQL(第二版)读书笔记
- spring boot 配置静态资源
- tinyumbrella 9(小雨伞)无法打开(Crash、自动关闭)的解决方法
- SQL Server中关于跟踪(Trace)那点事
- HDU 4849 nyist省赛选拔题目
- 每天一个Linux命令(7):mv命令
- Dev的GridControl数值列如何设置百分数
- org.hibernate.cfg.annotations.reflection.XMLContext$Default.getDelimitedIdentifier()Ljava/l
- 分析sql语句
- 后台无法通过$_FILES获取临时保存文件路径问题
- 利用JS输出ul下li的index索引值
- docker私服搭建的一些笔记
- ANDROID开发中,新手们常常碰到的bug和异常