分类目录归档:最短路

[BZOJ3482][COCI2013]hiperprostor

Orz Claris菊苣

对于这道题我们发现q很小,那么大概率是让你在线去做

然后我们知道n,m也很小,大概率是用n,m做一个dp

所以设f[i][j]表示从s出发,到达i,恰好经过jx边的最短路,利用spfa求出。

如果对于任意的i都有f[t][i]=\infty,则答案为无解。

继续阅读

[bzoj 1880][Sdoi2009]Elaxia的路线

Description

最近,Elaxia和w**的关系特别好,他们很想整天在一起,但是大学的学习太紧张了,他们 必须合理地安排两个人在一起的时间。Elaxia和w**每天都要奔波于宿舍和实验室之间,他们 希望在节约时间的前提下,一起走的时间尽可能的长。 现在已知的是Elaxia和w**所在的宿舍和实验室的编号以及学校的地图:地图上有N个路 口,M条路,经过每条路都需要一定的时间。 具体地说,就是要求无向图中,两对点间最短路的最长公共路径。

继续阅读

[bzoj 1295][SCOI2009]最长距离

Description

windy有一块矩形土地,被分为 N*M 块 1*1 的小格子。 有的格子含有障碍物。 如果从格子A可以走到格子B,那么两个格子的距离就为两个格子中心的欧几里德距离。 如果从格子A不可以走到格子B,就没有距离。 如果格子X和格子Y有公共边,并且X和Y均不含有障碍物,就可以从X走到Y。 如果windy可以移走T块障碍物,求所有格子间的最大距离。 保证移走T块障碍物以后,至少有一个格子不含有障碍物。

继续阅读

bzoj-USACO除草计划A

我已经做了30/30


继续阅读

Codeforces Round#372 Div.2

A. Crazy Computer

ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear!

More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then everything on the screen disappears and after that the word you have typed appears on the screen.

For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.

You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.

继续阅读

AIO2007 Solution

Wetlands

The Friends of Wetlands have dammed a creek to provide water for the nearby wetlands. During each month some rainwater flows into the dam, and then at the end of each month precisely 10 megalitres of water are released into the wetlands. If the dam contains less than 10 megalitres at the end of the month, the entire contents of the dam are released.

The local firefighters view the dam as a potential source of water to fight bushfires, and would like to know how much water there is likely to be in the dam in the height of the bushfire season in eight months' time. Your task is to use predicted rainfall figures to answer this question.

For example, suppose the predicted amounts of rainwater flowing into the dam for each of the eight months are 12, 9, 10, 7, 10, 13, 9 and 15 megalitres respectively. Assuming these figures are correct, after the first month the dam fills with 12 megalitres, and then 10 megalitres are taken (leaving 2). After the second month the dam fills to 2+9=11 megalitres, which is then reduced to 1. After the third month the dam fills to 11 megalitres and is again reduced to 1.

The fourth month is more interesting--here the dam only fills to 1+7=8 megalitres. Since the usual 10 megalitres cannot be taken, the dam is emptied completely. After the fifth month it fills to 10 and is again emptied, then it fills to 13 and reduces to 3, then fills to 12 and reduces to 2, and finally after the eighth month it fills to 17 and reduces to 7. Therefore your final answer for the firefighters is 7 megalitres.

继续阅读