您的位置:首页 > 其它

UVa 1388 - Graveyard

2013-03-31 20:34 302 查看
  将增加雕像后的间距看作1并用四舍五入的思想真是让人称赞,对两个雕像不会移动到同一位置的证明也很巧妙。

  代码如下:

View Code

#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
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+m) / n;
ans += fabs(pos - floor(pos+0.5)) / (n+m);
}
printf("%.4lf\n", ans*10000);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: