1316. Electronic Auction(树状数组)

1316

我想说 要不要这么坑 WA了一个小时啊 ,都快交疯了,拿着题解的代码交都WA 最后很无语的觉得题解都错了 重读了N遍题意 发现没读错啊 难道写题解的那个人和我都想错了??

最后把g++换个C++交吧 就这么A了 我#¥#%。。

这个题有要注意的地方 WA6  取整的地方要那样处理(看代码) 具体我也不知道为什么 

 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<algorithm>

 5 #include<stdlib.h>

 6 #include<cmath>

 7 using namespace std;

 8 #define N 1000000

 9 #define LL long long

10 #define lowbit(x) x&(-x)

11 LL re[N+10];

12 void add(int x,int d)

13 {

14     while(x)

15     {

16         re[x]+=d;

17         x-=lowbit(x);

18     }

19 }

20 LL getsum(int x)

21 {

22     LL s = 0;

23     while(x<=N)

24     {

25         s+=re[x];

26         x+=lowbit(x);

27     }

28     return s;

29 }

30 int main()

31 {

32     int num;

33     LL sum=0;

34     double k;

35     char s[20];

36     while(scanf("%s",s)!=EOF)

37     {

38         if(s[0]=='Q')

39         break;

40         else if(s[0]=='B')

41         {

42             scanf("%lf",&k);

43             int kk = floorl(k*100.0+0.5);

44             add(kk,1);

45         }

46         else if(s[0]=='D')

47         {

48             scanf("%lf",&k);

49             int kk = floorl(k*100.0+0.5);

50             add(kk,-1);

51         }

52         else

53         {

54             scanf("%lf %d",&k,&num);

55             int kk = floorl(k*100.0+0.5);

56             LL ss = getsum(kk);

57             if(ss>=num)

58             sum+=num;

59             else

60             sum+=ss;

61         }

62     }

63     printf("%.2lf\n",(double)sum/100.0+1e-9);

64     return 0;

65 }
View Code

 

 

你可能感兴趣的:(树状数组)