zoj 3693 Happy Great BG
Happy Great BG

Time Limit: 2 Seconds      Memory Limit: 65536 KB

The summer training of ZJU ICPC in July is about to end. To celebrate this great and happy day, the coaches of ZJU ICPC Team Navi and Fancy decided to BG everyone! Beside the two coaches, there are N participants. Those participants are divided into four groups to make problems for other groups.

After a brief discussion, they decided to go to Lou Wai Lou and have a great lunch. The cost for each person to have a meal in Lou Wai Lou is W yuan. Though it is very expensive, there is a special discount that Lou Wai Lou provided: for every K persons, one of them can have a free meal.

Navi and Fancy will equally pay all the cost for this great BG. Please help them to calculate how much money they each need to pay. By the way, please take care that the minimum monetary unit of RMB is fen (0.01 yuan).

Input

There are multiple test cases (no more than 100).

For each test case, there is only one line which contains three numbers N (1 <= N <= 100), W (0 <= W <= 10000) and K (1 < = K <= 100).

Output

For each test case, output the money a coach need to pay, rounded into 0.01 yuan.

Sample Input

3 70 3
32 999 1

Sample Output

140.00
0.00

今天浙大的月赛的一道水题,但是卡了很多人,我们队WA了很多次,就这题WA了9次,原因很简单,rounded into 0.01 yuan.这句话的意思是如果小数点后面有第三位,那么要进一位!开始以为是精确到两位小数,WA了之后,觉得应该是四舍五入,各种痛苦,最后还是运气好,clj想到了应该是不管怎么样,都要进一位,唉,其实这些排错的能力也挺重要的。虽然是水题……
 1 #include <iostream>
 2 #include <cmath>
 3 #include <cstdlib>
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <algorithm>
 7 #include <cctype>
 8 using namespace std;
 9 int main(void){
10   int n; double w; int  k;
11 
12   while (~scanf("%d%lf%d", &n, &w, &k)){
13     n+=2; int zu = n / k, mo = n - zu * k;
14     double s1 = 1.0 * (k - 1) * w * zu, s2 = 1.0 * mo * w, sum = s1 + s2;
15     sum = sum/2.0;
16     sum = (double)floor(sum * 100.0 + 0.9) / 100.0;
17     printf("%.2f\n", sum);
18   }
19   return 0;
20 }

记住四舍五入的写法,类比一下就是进位的。。

看到一大牛的回复后,我又思考了一下,还是很困惑。

第一点:如果真的是四舍五入的话,那么如果结果是xxxx.xx39999的话,那么按照我的方法就会输出xxxx.x(x+1);按照四舍五入的想法的话,就会输出xxxx.xx。

第二点:我按照四舍五入的想法,又重新交了两次代码,方法是加上eps,发现如果eps = 1e-12的话,就会WA,如果eps = 1e-9的话就过了……这是为毛……

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <cctype>
 6 #include <stack>
 7 #include <queue>
 8 #include <cmath>
 9 #include <algorithm>
10 #define lson l, m, rt<<1
11 #define rson m+1, r, rt<<1|1
12 using namespace std;
13 typedef long long int LL;
14 const int MAXN =  0x3f3f3f3f;
15 const int  MIN =  -0x3f3f3f3f;
16 const double eps = 1e-9;
17 
18 int main(void){
19 #ifndef ONLINE_JUDGE
20   freopen("zoj4966.in", "r", stdin);
21 #endif
22   int n, k; double w;
23   while (~scanf("%d%lf%d", &n, &w, &k)){
24     n += 2; int zu = n / k, mo = n - zu * k;
25     double s1 = 1.0 * (k - 1) * w * zu, s2 = 1.0 * mo * w, sum =s1+s2;
26     sum /= 2.0;
27     sum+=eps;
28     /*
29     sum = (double)floor(sum*100.0 + 0.9) / 100.0;
30     */
31     printf("%.2f\n", sum);
32   }
33 
34   return 0;
35 }

这是过了的代码……

还是很困惑,难道是zoj数据弱了么……比赛的时候又是运气好才过的么……糗……

posted on 2013-03-31 22:26  aries__liu  阅读(680)  评论(2编辑  收藏  举报