思维 UVALive 3708 Graveyard

 

题目传送门

 1 /*  2  题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离;  3  思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000即为距离;  4  详细解释:http://www.cnblogs.com/zywscq/p/4268556.html  5 */  6 #include <cstdio>  7 #include <iostream>  8 #include <algorithm>  9 #include <cmath> 10 #include <cstring> 11 #include <string> 12 #include <map> 13 #include <set> 14 #include <queue> 15 using namespace std; 16 17 const int MAXN = 1e4 + 10; 18 const int INF = 0x3f3f3f3f; 19 20 int main(void) //UVALive 3708 Graveyard 21 { 22 //freopen ("UVALive_3708.in", "r", stdin); 23 24 int n, m; 25 26 while (scanf ("%d%d", &n, &m) == 2) 27  { 28 double ans = 0.0, pos; 29 for (int i=1; i<n; ++i) 30  { 31 pos = (double) i / n * (n + m); 32 ans += fabs (pos - floor (pos + 0.5)) / (n + m); 33  } 34 35 printf ("%.4lf\n", ans * 10000); 36  } 37 38 return 0; 39 }

 

你可能感兴趣的:(live)