LA 3708 - Graveyard 墓地雕塑
2013-08-02 20:44
274 查看
点击打开链接
Programming contests became so popular in the year 2397 that the governor of New Earck -- the largest human-inhabited planet of the galaxy -- opened a special Alley of Contestant Memories (ACM) at the local graveyard. The ACM encircles a green park, and
holds the holographic statues of famous contestants placed equidistantly along the park perimeter. The alley has to be renewed from time to time when a new group of memorials arrives.
When new memorials are added, the exact place for each can be selected arbitrarily along the ACM, but the equidistant disposition must be maintained by moving some of the old statues along the alley.
Surprisingly, humans are still quite superstitious in 24th century: the graveyard keepers believe the holograms are holding dead people souls, and thus always try to renew the ACM with minimal possible movements of existing statues (besides, the holographic
equipment is very heavy). Statues are moved along the park perimeter. Your work is to find a renewal plan which minimizes the sum of travel distances of all statues. Installation of a new hologram adds no distance penalty, so choose the places for newcomers
wisely!
-- the number of holographic statues initially located at the ACM, andm
-- the number of statues to be added (2
n
1000,
1
m
1000)
. The length of the alley along the park perimeter is exactly 10 000 feet.
Pictures show the first three examples. Marked circles denote original statues, empty circles denote new equidistant places, arrows denote movement plans for existing statues.
题意:在一个周长为10000的圆上等距分布着n个雕塑。现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周上均匀分布。这就需要移动其中一些原有的雕塑。要求n个雕塑移动的总距离最小。另其中一个雕塑不动,作为坐标原点,其他雕塑按照逆时针顺序标上到原点的距离标号。然后,我们把每个雕塑移动到离它最近的距离,如果没有两个雕塑移动到相同的位置,那么这样的移动一定是最优的。
3708 - Graveyard
Time limit: 3.000 secondsProgramming contests became so popular in the year 2397 that the governor of New Earck -- the largest human-inhabited planet of the galaxy -- opened a special Alley of Contestant Memories (ACM) at the local graveyard. The ACM encircles a green park, and
holds the holographic statues of famous contestants placed equidistantly along the park perimeter. The alley has to be renewed from time to time when a new group of memorials arrives.
When new memorials are added, the exact place for each can be selected arbitrarily along the ACM, but the equidistant disposition must be maintained by moving some of the old statues along the alley.
Surprisingly, humans are still quite superstitious in 24th century: the graveyard keepers believe the holograms are holding dead people souls, and thus always try to renew the ACM with minimal possible movements of existing statues (besides, the holographic
equipment is very heavy). Statues are moved along the park perimeter. Your work is to find a renewal plan which minimizes the sum of travel distances of all statues. Installation of a new hologram adds no distance penalty, so choose the places for newcomers
wisely!
Input
The input file contains several test cases, each of them consists of a a line that contains two integer numbers:n-- the number of holographic statues initially located at the ACM, andm
-- the number of statues to be added (2
n
1000,
1
m
1000)
. The length of the alley along the park perimeter is exactly 10 000 feet.
Output
For each test case, write to the output a line with a single real number -- the minimal sum of travel distances of all statues (in feet). The answer must be precise to at least 4 digits after decimal point.Pictures show the first three examples. Marked circles denote original statues, empty circles denote new equidistant places, arrows denote movement plans for existing statues.
Sample Input
2 1 2 3 3 1 10 10
Sample Output
1666.6667 1000.0 1666.6667 0.0
题意:在一个周长为10000的圆上等距分布着n个雕塑。现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周上均匀分布。这就需要移动其中一些原有的雕塑。要求n个雕塑移动的总距离最小。另其中一个雕塑不动,作为坐标原点,其他雕塑按照逆时针顺序标上到原点的距离标号。然后,我们把每个雕塑移动到离它最近的距离,如果没有两个雕塑移动到相同的位置,那么这样的移动一定是最优的。
#include<stdio.h> #include<math.h> int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { double ans=0; for(int i=1;i<n;i++) { double pos=(double)i/n*(n+m);//计算每个需要移动的雕塑的坐标 ans+=fabs(pos-floor(pos+0.5))/(n+m);//pos进行四舍五入 } printf("%.4lf\n",ans*10000); } return 0; }
相关文章推荐
- 【贪心】【POJ3154】墓地雕塑(Graveyard, NEERC 2006, LA 3708)需要稍稍加工的(先贪心,再确保能这样贪(可行性&&如果可行必定最优&&非证明最优性)的题)(K)
- UVa 1388 Graveyard 墓地雕塑
- (LA 3708)墓地雕塑(Graveyard )
- LA3708 Graveyard 墓地雕塑
- LA3708 Graveyard 墓地雕塑-水题
- LA 3708 Graveyard 墓地雕塑 NEERC 2006
- graveyard,neerc(墓地雕塑)
- 墓地雕塑(Graveyard, NEERC 2006, LA 3708)
- [ACM_数学] LA 3708 Graveyard [墓地雕塑 圈上新加点 找规律]
- LA3708 Graveyard 墓地雕塑
- Graveyard(墓地雕塑)
- 墓地雕塑(Graveyard, NEERC 2006, LA 3708)
- 墓地雕塑(Graveyard, NEERC 2006, LA 3708)
- 【贪心】【POJ3154】墓地雕塑(Graveyard, NEERC 2006, LA 3708)需要稍稍加工的(先贪心,再确保能这样贪(可行性&&如果可行必定最优&&非证明最优性)的题)(K)
- LA3708 Graveyard 墓地雕塑
- 例题1.4 墓地雕塑 UVa1388
- 【算法设计与分析】墓地雕塑
- 墓地雕塑(LA 3708)
- 墓地雕塑-LA3708
- C/C++每日小练(七)——墓地雕塑