首页 > 其他 > 详细

HDU 4803 贪心

时间:2015-02-15 13:29:46      阅读:219      评论:0      收藏:0      [点我收藏+]

尽可能的让当前的平均值接近最后的平均值才能最快达到终点的情况

 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 }

 

HDU 4803 贪心

原文:http://www.cnblogs.com/CSU3901130321/p/4292773.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!