• BestCoder Round #2


    TIANKENG’s restaurant http://acm.hdu.edu.cn/showproblem.php?pid=4883

    竟然暴力1.44*10^7  还要*T=100  竟然过了

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define mt(a,b) memset(a,b,sizeof(a))
     5 using namespace std;
     6 const int M=1450;
     7 int sum[M];
     8 int main(){
     9     int t,n;
    10     while(~scanf("%d",&t)){
    11         while(t--){
    12             scanf("%d",&n);
    13             mt(sum,0);
    14             while(n--){
    15                 int add,sx,sy,ex,ey;
    16                 scanf("%d %d:%d %d:%d",&add,&sx,&sy,&ex,&ey);
    17                 sx=sx*60+sy+1;
    18                 ex=ex*60+ey;
    19                 for(int i=sx;i<=ex;i++) sum[i]+=add;
    20             }
    21             int big=0;
    22             for(int i=0;i<M;i++){
    23                 big=max(big,sum[i]);
    24             }
    25             printf("%d
    ",big);
    26         }
    27     }
    28     return 0;
    29 }
    View Code

    线段树RE,因为题目中会出现sx>ex。判了就过。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define mt(a,b) memset(a,b,sizeof(a))
     5 #define lrrt int L,int R,int rt
     6 #define iall 1,n,1
     7 #define imid int mid=(L+R)>>1
     8 #define lson L,mid,rt<<1
     9 #define rson mid+1,R,rt<<1|1
    10 using namespace std;
    11 const int M=1450;
    12 int tree[M<<2];
    13 void pushdown(int rt){
    14     if(tree[rt]){
    15         tree[rt<<1]+=tree[rt];
    16         tree[rt<<1|1]+=tree[rt];
    17         tree[rt]=0;
    18     }
    19 }
    20 void update(int x,int y,int val,lrrt){
    21     if(x<=L&&R<=y){
    22         tree[rt]+=val;
    23         return ;
    24     }
    25     pushdown(rt);
    26     imid;
    27     if(mid>=x) update(x,y,val,lson);
    28     if(mid<y)  update(x,y,val,rson);
    29 }
    30 int big;
    31 void query(lrrt){
    32     if(L==R){
    33         big=max(big,tree[rt]);
    34         return ;
    35     }
    36     imid;
    37     pushdown(rt);
    38     query(lson);
    39     query(rson);
    40 }
    41 int main(){
    42     int t,n=1439,m;
    43     while(~scanf("%d",&t)){
    44         while(t--){
    45             scanf("%d",&m);
    46             mt(tree,0);
    47             while(m--){
    48                 int add,sx,sy,ex,ey;
    49                 scanf("%d %d:%d %d:%d",&add,&sx,&sy,&ex,&ey);
    50                 sx=sx*60+sy;
    51                 ex=ex*60+ey-1;
    52                 if(sx>ex) continue;
    53                 update(sx,ex,add,iall);
    54             }
    55             big=0;
    56             query(iall);
    57             printf("%d
    ",big);
    58         }
    59     }
    60     return 0;
    61 }
    View Code

     正解是o(n)算法,标记,左++,右--。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define mt(a,b) memset(a,b,sizeof(a))
     5 using namespace std;
     6 const int M=1450;
     7 int sum[M];
     8 int main(){
     9     int t,n=1439,m;
    10     while(~scanf("%d",&t)){
    11         while(t--){
    12             scanf("%d",&m);
    13             mt(sum,0);
    14             while(m--){
    15                 int add,sx,sy,ex,ey;
    16                 scanf("%d %d:%d %d:%d",&add,&sx,&sy,&ex,&ey);
    17                 sx=sx*60+sy;
    18                 ex=ex*60+ey;
    19                 if(sx>ex) continue;
    20                 sum[sx]+=add;
    21                 sum[ex]-=add;
    22             }
    23             int big=0;
    24             int now=0;
    25             for(int i=0;i<M;i++){
    26                 now+=sum[i];
    27                 big=max(big,now);
    28             }
    29             printf("%d
    ",big);
    30         }
    31     }
    32     return 0;
    33 }
    View Code

    end

  • 相关阅读:
    Android CTS(frome google)
    Android CTS
    【Linux】- 修改系统时间与时区
    【Linux】- CentOS查看IP
    【Linux】- Ubutnu UFW防火墙的简单设置
    【Linux】- Ubuntu安装nginx
    【Linux】- apt-get命令
    【Linux】- Ubuntu搭建FTP服务器
    【Linux】- Ubuntu 配置mysql远程访问
    【Linux】- Ubuntu安装redis,并开启远程访问
  • 原文地址:https://www.cnblogs.com/gaolzzxin/p/3872090.html
Copyright © 2020-2023  润新知