zoj 3693 Happy Great BG
March 31, 2013
zoj
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). 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). For each test case, output the money a coach need to pay, rounded into 0.01 yuan.
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
using namespace std;
int main(void){
int n; double w; int k;
while (~scanf("%d%lf%d", &n, &w, &k)){
n+=2; int zu = n / k, mo = n - zu * k;
double s1 = 1.0 * (k - 1) * w * zu, s2 = 1.0 * mo * w, sum = s1 + s2;
sum = sum/2.0;
sum = (double)floor(sum * 100.0 + 0.9) / 100.0;
printf("%.2f\n", sum);
}
return 0;
}
记住四舍五入的写法,类比一下就是进位的。。 看到一大牛的回复后,我又思考了一下,还是很困惑。 第一点:如果真的是四舍五入的话,那么如果结果是xxxx.xx39999的话,那么按照我的方法就会输出xxxx.x(x+1);按照四舍五入的想法的话,就会输出xxxx.xx。 第二点:我按照四舍五入的想法,又重新交了两次代码,方法是加上eps,发现如果eps = 1e-12的话,就会WA,如果eps = 1e-9的话就过了……这是为毛……
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long int LL;
const int MAXN = 0x3f3f3f3f;
const int MIN = -0x3f3f3f3f;
const double eps = 1e-9;
int main(void){
#ifndef ONLINE_JUDGE
freopen("zoj4966.in", "r", stdin);
#endif
int n, k; double w;
while (~scanf("%d%lf%d", &n, &w, &k)){
n += 2; int zu = n / k, mo = n - zu * k;
double s1 = 1.0 * (k - 1) * w * zu, s2 = 1.0 * mo * w, sum =s1+s2;
sum /= 2.0;
sum+=eps;
/*
sum = (double)floor(sum*100.0 + 0.9) / 100.0;
*/
printf("%.2f\n", sum);
}
return 0;
}
这是过了的代码…… 还是很困惑,难道是zoj数据弱了么……比赛的时候又是运气好才过的么……糗……