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

建议使用的浏览器:

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

2590:Building roads

题目描述
There is a circle-shape lake in a beautiful town. And along the lake, there are N cities, living lots of pigs.
In 2008, the number of pigs is growing so faster that the government decide to transfer some pigs from some cities to others. And they want to make that each city has the same number of pigs.
Before the transfer, the government has to build some roads between cities. For example, if we want to move some pigs from city A to city B, we have to build a road between A and B. Now the government wants to save more money for the National's Day, so they want to build roads as few as possible, i.e, they want to know how many roads at least they have to build to make that each city has the same number of pigs.



Giving the initial number of pigs of each city, you should tell me the least number of roads have to build. If it is impossible to make each city has the same number of pigs, output "Impossible".
输入解释
There will be multiple input sets. The first line of input will contain a integer K, means the number of sets.
Input for each set is a positive integer n(means the number of cities, 1 <= n <= 10000) on a line by itself, followed one line containing some positive integers(no more than 10000), indicate the cities' initial number of pigs.
输出解释
Output for each input set should be one line containing a positive integer R, means the least number of roads have to build, output "Impossible" if it is impossible to make each city has the same number of pigs
输入样例
4
3
1 2 3
3
2 2 2
4
1 3 1 3
3
1 3 3
输出样例
1
0
2
Impossible
来自杭电HDUOJ的附加信息
Recommend lcy

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

源链接: HDU-2590

最后修改于 2020-10-25T22:54:58+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 32768/32768K(Java/Others)