POJ 3154/模拟(最小墓地移动长度)
2011-06-04 11:32
190 查看
原来有a个坑,现在要添加b个坑,前后每个坑的间距都要是一样的,环形圈的长度为10000,求最小的坑移动长度
原来肯定有一个坑不动,剩下a-1个坑,a+b个坑的平均间距为average,对于这a-1个坑,如果它的坐标x满足:average*j<=x<=average*(j+1),则min(x-average*j,average*(j+1)-x)则为此坑移动距离
Sample Input sample input #1 2 1 sample input #2 2 3 sample input #3 3 1 sample input #4 10 10 Sample Output sample output #1 1666.6667 sample output #2 1000.0 sample output #3 1666.6667 sample output #4 0.0
#include "stdio.h" int main() { int before,after; double be,af,sum=0.0; scanf("%d%d",&before,&after); be=(double)10000/before; af=(double)10000/(before+after); int j=1; for(int i=1;i<before;i++) { double p1,p2; p1=i*be; while(1) { p2=j*af; if(p2<=p1&&p1<=p2+af)break; j++; } if(p1-p2<p2+af-p1)sum+=p1-p2; else sum+=p2+af-p1; } if((int)sum==sum)printf("%d.0",(int)sum); else printf("%.4lf",sum); return 0; }
相关文章推荐
- POJ 3154 Graveyard 添加m个雕塑后仍旧使每个雕塑在圆圈上距离相等 需要移动的最小距离
- poj 1920 汉诺塔移动到某一种指定位置的最小步数
- poj 1961 Period【求前缀的长度,以及其中最小循环节的循环次数】
- poj 1080 DP 2个串,中间可加‘-’变成长度相同的串,求最小代价
- poj-1548-Robots- 贪心+模拟 / 最小路径覆盖
- POJ 3154 墓地雕塑(很厉害的两行代码)
- POJ 2349 Arctic Network(Kruskal求最小生成树第k条边的长度)
- 1/21集训二 模拟+贪心 F.(贪心 处理有长度和重量的木棍,求最小处理机器的次数)Wooden Sticks
- (哈夫曼树10.3.1)POJ 3253 Fence Repair(计算带权路径长度最小的哈夫曼树)
- poj 1734 Floyd输出路径(长度大于等于3的最小圈)
- POJ 1804(最小相邻数移动)
- UVA-1388 && POJ-3154 墓地雕塑(数学)
- poj_1325_最小点覆盖
- POJ 3415 Common Substrings (求长度大于K的公共子串个数,5级)
- poj 3393 Lucky and Good Months by Gregorian Calendar(模拟)
- POJ 2253 Frogger(最小生成树)
- poj 1734 Sightseeing trip 扩展floyd求最小环
- Web Navigation poj 1028 模拟
- (kruscal12.1.1)POJ 2421 Constructing Roads(使用kruscal算法来生成最小生成树&&计算最小带权路径和)
- POJ 2665 模拟,,