BestCoder Round #2
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的更多相关文章
- BestCoder Round #89 02单调队列优化dp
1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01 HDU 5944 水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...
- BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元
BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy Init函数 然后统计就ok B. 博弈 题 不懂 推了半天的SG..... 结果这 ...
- bestcoder Round #7 前三题题解
BestCoder Round #7 Start Time : 2014-08-31 19:00:00 End Time : 2014-08-31 21:00:00Contest Type : ...
- 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 ...
- Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...
- 暴力+降复杂度 BestCoder Round #39 1002 Mutiple
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...
- BestCoder Round #88
传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...
- 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 ( ...
- 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 ...
随机推荐
- JS数据类型转换
JS 数据类型转换 方法主要有三种 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数,后者把 ...
- UI1_应用的程序的生命周期
// // AppDelegate.m // UI1_应用的程序的生命周期 // // Created by zhangxueming on 15/6/29. // Copyright (c) 201 ...
- 杭电ACM2057--A + B Again
这是题目 A + B Again 这是源代码: #include <stdio.h> int main() { __int64 a,b; while (scanf("%I64X ...
- How to Get Rid of /wordpress/ From your WordPress Site URL
I brought up a website using wordpress, but I had to visit my website in a way I don't like -- www.e ...
- mongodb gdal 矢量数据格式驱动
写了个mongodb的gdal driver,放在了github上,如果你需要,欢迎加入mongogis group. 直接的效果是使得QGIS, GeoServer, MapServer, ArcG ...
- mstsc命令详解
1: 在xp sp2中用mstsc /console命令可以登录到远程桌面的控制台(和在电脑前以同一用户登录),xp升级到sp3后,不能这样用了.sp3中命令应该换成mstsc /admin. 2: ...
- lnmp下配置虚拟主机
一:首先熟悉几个命令 which php ---> which是通过 PATH环境变量到该路径内查找可执行文件,所以基本的功能是寻找可执行文件 whereis php ----& ...
- 如何通过jquery隐藏和显示元素
以下几种方式可以隐藏一个元素:1,CSS display的值是none.2,type="hidden"的表单元素.3,宽度和高度都显式设置为0.4,一个祖先元素是隐藏的,该元素是不 ...
- ThoughtWorks FizzBuzzWhizz 代码实现
当时拉钩网ThoughtWorks出了一道面试题(https://www.jinshuju.net/f/EGQL3D),本人用PHP实现了一下,当时忘记了把代码分享出来,今天特来补上. FizzBuz ...
- How to: Enable and Disable an Action Pane Button on a List Page [AX 2012]
Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynami ...