标签:
尽可能的让当前的平均值接近最后的平均值才能最快达到终点的情况
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 // freopen("a.in" , "r" , stdin); 9 int x , y; 10 while(scanf("%d%d" , &x , &y) == 2) 11 { 12 if(y<x){ 13 puts("-1"); 14 continue; 15 } 16 double ave = (y+0.999999)/x; 17 double cur = 1.0; 18 int cnt = x-1 , ax = 1; 19 while(1) 20 { 21 if(ax == x+1) break; 22 int t = (int)(ave*ax - cur); 23 cur += t , cnt += t; 24 cur += cur/ax; 25 ax++; 26 } 27 printf("%d\n" , cnt); 28 } 29 return 0; 30 }
标签:
原文地址:http://www.cnblogs.com/CSU3901130321/p/4292773.html