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

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

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int M=;
int sum[M];
int main(){
int t,n;
while(~scanf("%d",&t)){
while(t--){
scanf("%d",&n);
mt(sum,);
while(n--){
int add,sx,sy,ex,ey;
scanf("%d %d:%d %d:%d",&add,&sx,&sy,&ex,&ey);
sx=sx*+sy+;
ex=ex*+ey;
for(int i=sx;i<=ex;i++) sum[i]+=add;
}
int big=;
for(int i=;i<M;i++){
big=max(big,sum[i]);
}
printf("%d\n",big);
}
}
return ;
}

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

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define mt(a,b) memset(a,b,sizeof(a))
#define lrrt int L,int R,int rt
#define iall 1,n,1
#define imid int mid=(L+R)>>1
#define lson L,mid,rt<<1
#define rson mid+1,R,rt<<1|1
using namespace std;
const int M=;
int tree[M<<];
void pushdown(int rt){
if(tree[rt]){
tree[rt<<]+=tree[rt];
tree[rt<<|]+=tree[rt];
tree[rt]=;
}
}
void update(int x,int y,int val,lrrt){
if(x<=L&&R<=y){
tree[rt]+=val;
return ;
}
pushdown(rt);
imid;
if(mid>=x) update(x,y,val,lson);
if(mid<y) update(x,y,val,rson);
}
int big;
void query(lrrt){
if(L==R){
big=max(big,tree[rt]);
return ;
}
imid;
pushdown(rt);
query(lson);
query(rson);
}
int main(){
int t,n=,m;
while(~scanf("%d",&t)){
while(t--){
scanf("%d",&m);
mt(tree,);
while(m--){
int add,sx,sy,ex,ey;
scanf("%d %d:%d %d:%d",&add,&sx,&sy,&ex,&ey);
sx=sx*+sy;
ex=ex*+ey-;
if(sx>ex) continue;
update(sx,ex,add,iall);
}
big=;
query(iall);
printf("%d\n",big);
}
}
return ;
}

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

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
const int M=;
int sum[M];
int main(){
int t,n=,m;
while(~scanf("%d",&t)){
while(t--){
scanf("%d",&m);
mt(sum,);
while(m--){
int add,sx,sy,ex,ey;
scanf("%d %d:%d %d:%d",&add,&sx,&sy,&ex,&ey);
sx=sx*+sy;
ex=ex*+ey;
if(sx>ex) continue;
sum[sx]+=add;
sum[ex]-=add;
}
int big=;
int now=;
for(int i=;i<M;i++){
now+=sum[i];
big=max(big,now);
}
printf("%d\n",big);
}
}
return ;
}

end

BestCoder Round #2的更多相关文章

  1. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  2. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  3. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  4. Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  5. Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  6. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  7. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  8. BestCoder Round #88

    传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...

  9. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  10. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

随机推荐

  1. Ruby on Raisl应用(一):在Rails上配置Mongoid+Mongodb

    一. 概述 最近考虑用ruby on rails 搭建一套Blog系统,前端考虑用Bootstrap,数据库用Mongodb.由于之前没有相关应用经验.先记录下整个项目过程. 现有资源: Mac 笔记 ...

  2. C#DateTime的用法

    本文较详细地介绍了C#的DateTime对象的使用方法.DateTime.Now.ToShortTimeString() DateTime dt = DateTime.Now; dt.ToString ...

  3. iOS 最新版 CocoaPods 的安装使用

    当在开发iOS应用时,会经常使用到很多的第三方开源类库,一般的方法是直接从GitHub下载,然后拖到项目中使用,如果该开源类库不依赖其他的类库,就可以直接使用:如果该开源类库还依赖一些其他的类库,则需 ...

  4. JAVA:类的三大特征,抽象类,接口,final关键字<3>

    一.类的三大特征 1.封装性 (1).什么是封装 封装就是把抽象出的数据和对数据的操作封装在一起, 数据被保护在内部, 程序的其他部分只有通过被授权的操作(成员方法), 才能对数据进行操作. (2). ...

  5. THREE.js代码备份——线框cube、按键、鼠标控制

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js canvas - g ...

  6. Mac系统Finder访问资源库文件夹

    Mac在Lion版本之后,默认隐藏了“资源库”文件夹,如果有时我们又需要访问它,该怎么办呢? 方法一 打开“Finder”,打开“前往”菜单时按住“Option”键. 方法二 我们也可设置Finder ...

  7. 《Java核心技术与最佳实践》读书笔记

    第一章 Java7新语法 1.switch中使用字符串 2.增加二进制表示0b10101010:数字字面量允许直径使用下划线12_34_90 3.一个catch字句捕获多个异常,多个异常之间用|分隔 ...

  8. 例题6-4 Broken Keyboard UVa11988

    题目分析: 起初这道题目没有做出来,原因是我一直想把整块区域一并插入,而不是逐个插入.今后做题应该注意这个问题,把问题分解去考虑,也许会少走许多弯路. 下边附上AC代码 #include <cs ...

  9. 更改windows服务的配置文件app.config

    /// <summary> /// 获取每次处理记录数 /// </summary> /// <returns></returns> private s ...

  10. centos5.4下mysql主从复制

    centos5.4下mysql主从复制配置分享. 本文转自:http://www.jbxue.com/article/771.html 安装环境:centos 5.4 mysql版本:mysql 5. ...