HDU - 6252
Mr. Panda and God Sheep are roommates and working in the same company. They always take subway to work together. There are NN subway stations on their route, numbered from 1 to NN. Station 1 is their home and station NN is the company.
One day, Mr. Panda was getting up later. When he came to the station, God Sheep has departed XX minutes ago. Mr. Panda was very hurried, so he started to chat with God Sheep to communicate their positions. The content is when Mr. Panda is between station AA and BB, God Sheep is just between station CC and DD.
BB is equal to A+1A+1 which means Mr. Panda is between station AA and A+1A+1exclusive, or BB is equal to AA which means Mr. Panda is exactly on station AA. Vice versa for CC and DD. What’s more, the communication can only be made no earlier than Mr. Panda departed and no later than God Sheep arrived.
After arriving at the company, Mr. Panda want to know how many minutes between each adjacent subway stations. Please note that the stop time at each station was ignored.
Input
The first line of the input gives the number of test cases, TT. TT test cases follow.
Each test case starts with a line consists of 3 integers NN, MM and XX, indicating the number of stations, the number of chat contents and the minute interval between Mr. Panda and God Sheep. Then MM lines follow, each consists of 4 integers AA, BB, CC, DD, indicating each chat content.
1≤T≤301≤T≤30
1≤N,M≤20001≤N,M≤2000
1≤X≤1091≤X≤109
1≤A,B,C,D≤N1≤A,B,C,D≤N
A≤B≤A+1A≤B≤A+1
C≤D≤C+1C≤D≤C+1
Output
For each test case, output one line containing “Case #x: y”, where xx is the test case number (starting from 1) and yy is the minutes between stations in format t1,t2,...,tN−1t1,t2,...,tN−1. titi represents the minutes between station ii and i+1i+1. If there are multiple solutions, output a solution that meets 0 Sample Input Sample Output Hint 题目大意: 给出两个人之间的距离以及在一些相同的时刻,他们所属的区段,问这些区段的长度 思路: 对于每一组给出的区段信息,我们都可以得到: d-a>=x c-b<=x 当a,b重叠或者c,d重叠时等号无法取到 也就是d-a>=x+1&&c-b<=x-1 与此同时,任意两点之间的距离还要大于1,也就是 x-(x-1)>=1 根据上述这些式子进行差分约束 AC代码: 2
4 3 2
1 1 2 3
2 3 2 3
2 3 3 4
4 2 2
1 2 3 4
2 3 2 3
Case #1: 1 3 1
Case #2: IMPOSSIBLE
In the second test case, when God Sheep passed the third station, Mr. Panda hadn’t arrived the second station.
They can not between the second station and the third station at the same time.
#include