hdu1202 The calculation of GPA ——水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1202

题目大意:先计算出学分和点数的乘积的和,然后在除以学分之和。

思路:

  很简单。只能说这道题目比较坑……不说什么了

  本来是早上起来想写道水题,练练手,结果碰见这种题目,刚才我还无聊的测试了很多次,交了N遍,发现这么个坑的问题,感觉这种题目很没有意思……

 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 const int dir[8][2] = {{0,1},{1,0},{0,-1},{-1,0},{-1,1},
18   {1,1},{1,-1},{-1,-1}};
19 
20 int main(void){
21 #ifndef ONLINE_JUDGE
22   freopen("hdu1202.in", "r", stdin);
23 #endif
24   int t;
25   while (~scanf("%d", &t)){
26     double cnt = 0, cnt1 = 0; double s, p;
27     for (int i = 0; i < t; ++i){
28       cin >> s >> p; cnt += s;
29       if (p>=90 && p <= 100) cnt1 += 4.0 * s;
30       else if (p>=80) cnt1 += 3.0 * s;
31       else if (p>=70) cnt1 += 2.0 * s;
32       else if (p>=60) cnt1 += 1.0 * s;
33       else;
34     }
35     double ans = 0.0;
36     ans = cnt1 / cnt;
37     if (fabs(cnt1) < eps) printf("-1\n");
38     else printf("%.2f\n", ans);
39   }
40 
41   return 0;
42 }

  开始没有考虑到学分可能都为0的情况,判断fabs(ans) < eps ,OLE了,因为学分可能为0,这个时候0就做分母了。

  也有的人说这种题目很没意思,要考虑很多没有意义的情况,感觉比较坑……其实这也可能是考察人的思维的严谨程度的吧,我也WA了N次……开始也以为这道题目比较坑,无聊在OJ上测试了N遍之后,发现其实关键还是自己的错……不冷静,思维不严谨。

posted on 2013-04-15 20:39  aries__liu  阅读(421)  评论(0编辑  收藏  举报