hdu5714
来源:互联网 发布:英语书籍阅读软件 编辑:程序博客网 时间:2024/05/05 03:48
先开始我是思考在每行的情况忽略了小明这个关键因素,这题的关键就是注意一个技巧将分散的变量集中在一个点上这是一个常用技巧。。
注意在离散化话一下。
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int dir[2][40000],all[40000];struct pos{ int kind,addkind,p;};int t,n,tot;pos q[80050];bool com(pos a,pos b){ return a.p<b.p;}int main(){ scanf("%d",&t); int k=1; while(t--) { tot=0; scanf("%d",&n); while(n--) { int x,y,z,d; scanf("%d%d%d%d",&x,&y,&z,&d); if(z*2<(y-x))continue; if(d==1) { q[tot].p=y-z; q[tot].kind=1; q[tot++].addkind=1; q[tot].p=x+z+1; q[tot].kind=1; q[tot++].addkind=-1; } else { q[tot].p=x+z; q[tot].kind=0; q[tot++].addkind=1; q[tot].p=y-z-1; q[tot].kind=0; q[tot++].addkind=-1; } } sort(q,q+tot,com); int endpos=0; for(int i=0;i<tot;i++) { if(i!=0&&q[i].p>q[i-1].p) endpos++; dir[q[i].kind][endpos]+=q[i].addkind; } int ans=0; for(int i=0;i<=endpos;i++) { ans+=dir[1][i]; all[i]=ans; } int maxx=-1; ans=0; for(int i=endpos;i>=0;i--) { ans+=dir[0][i]; maxx=max(ans,maxx); all[i]+=maxx; } maxx=-1; for(int i=0;i<=endpos;i++) maxx=max(all[i],maxx); printf("Case #%d:\n%d\n",k++,maxx); for(int i=0;i<=endpos;i++) { all[i]=0; dir[0][i]=0; dir[1][i]=0; } } return 0; }
阅读全文
0 0
- hdu5714
- hdu5714 百度之星复赛C
- hdu5714 思维+区间内线段最
- 2016暑期集训11C hdu5714 拍照
- 怎样理解阻塞非阻塞与同步异步的区别?
- Java读书笔记——04 输入输出
- disconf启动流程
- AIDL实现不同应用之间跨进程通讯及传递与返回各种数据类型和远程接口回调
- 【转】关于HTTP协议,一篇就够了
- hdu5714
- python 中的selenium模块使用方法
- ansible2.4学习(安装部署)
- Python学习笔记(四)字符串
- 关于安装Homebrew
- Android中用inteng启用不同应用中的活动
- 逗比日记_参考的小习惯
- XYNUOJ 24 Point game 搜索
- 微信小程序-tab选项卡