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. [javascript|基本概念]学习笔记

    1/语法 a.区分大小写 b.标识符(首字符必须是字母/"_"/"$",其他可为字母/"_"/"$"/数字,不能用关键字 ...

  2. poj 3268 Silver Cow Party

                                                                                                       S ...

  3. const char *p、char const *p、char * const p的区别?

    const char *p和char const *p是一样的,都表示定义一个指向字符常量的指针,指针的内容(字符)不可变.char * const p表示一个指向字符的指针常量,字符可以改变,但是指 ...

  4. Spring Security (Acegi)的登陆配置

    简短记录一下: 在authenticationProcessingFilter这个bean中,如果没有配置<property name="alwaysUseDefaultTargetU ...

  5. 我开发了一个产品--Markdown Notes

    大家好,我开发了一个工具类软件产品--Markdown Notes,中文名是Markdown笔记.想写一篇有关它的文章,目的就是为了推广.推广.推广:) BTW:本文就是用这个工具所写的.

  6. css透明(支持各浏览器)

    opacity: 0.4;filter: progid:DXImageTransform.Microsoft.Alpha(opacity=40); -ms-filter: "progid:D ...

  7. 第六周 N题

    Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (h ...

  8. java之jar命令详解

    1. JAR 文件包 JAR 文件就是 Java Archive File,顾名思意,它的应用是与 Java 息息相关的,是 Java 的一种文档格式.JAR 文件非常类似 ZIP 文件——准确的说, ...

  9. Oracle 主键

    给student 表产生 自增的序列主键 increment ; ----IBATIS简单入门教程http://www.cnblogs.com/ycxyyzw/archive/2012/10/13/2 ...

  10. 虚拟机Linux下找不到/dev/cdrom

    问题描述: 笔者欲更新一下VMwareTools,结果发现虚拟机Linux上找不到设备"/dev/cdrom",当然也就不能通过命令"mount /dev/cdrom / ...