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. php中simplexml_load_string使用实例

    先用一段代码重现一下问题 乍一看,结果很让人费解: 代码如下 复制代码 <?php $string = <<<EOF <data> <foo><b ...

  2. c# js调用AjaxPro方法出错解析

    公司的项目的框架中有一部分用到了AjaxPro这个方法,看到这个方法的我一脸懵逼,老老实实去百度了一下. AjaxPro是.NET平台下的一个回调式AJAX框架,使用简单,功能强大.顾名思义ajax, ...

  3. (转)TeamCity配置笔记

    1.编译sln 2.发布网站 3.重复代码检测 4.代码分析 5.单元测试&覆盖率测试 查看代码覆盖率 7.代码签入时自动触发编译 8.通知 1.在teamcity安装目录中找到TrayNot ...

  4. linux install mpi4py

    Downloading The MPI for Python package is available for download at the project website generously h ...

  5. 《RHEL6硬盘的分区和swap分区管理》——硬盘分区的大总结

    首先介绍下几个简单的命令: free查看当前系统内存的使用情况 查看分区的使用情况:T类型.H显示大小以G,M 查看系统所有硬盘的分区信息:分区的没分区的都显示出来了 开始分区:为什么要加cu  不加 ...

  6. System Generator入门

      System generator 安装之后会在Simulin模块库中添加一些Xilinx FPGA专用的模块库,包括Basic Element,Communication,Control Logi ...

  7. 如何判断PHP 是ts还是nts版的

    通过phpinfo(); 查看其中的 Thread Safety 项,这个项目就是查看是否是线程安全,如果是:enabled,一般来说应该是ts版,否则是nts版.

  8. Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建教程

    这篇文章主要介绍了Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建教程,需要的朋友可以参考下 准备篇 一.环境说明: 操作系统:Windows Server 201 ...

  9. Delphi XE5教程9:基本语法元素

    内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误!也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者可 ...

  10. Use Sandcastle Help File Builder to generate help document

    http://shfb.codeplex.com/ Note: If the the help file contains the text "[Missing <param> ...