HDU 5714 拍照 [杂题] [离散化]
来源:互联网 发布:上海逸晗网络 编辑:程序博客网 时间:2024/06/05 08:26
拍照
Time Limit: 3000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u
Description
小明在旅游的路上看到了一条美丽的河,河上有许多船只,有的船只向左航行,有的船只向右航行。小明希望拍下这一美丽的风景,并且把尽可能多的船只都完整地拍到一张照片中。
小明位于河的边上,并且可以在河边的任意位置进行拍照,照相机的视野恰好为90度角,只能以垂直于河边的方向进行拍照。河上的船只全都可看作是平行于河边的一条线段,跟河边的距离各不相同,有的正在向左移动,有的正在向右移动,但移动速度恰好都是一样的。小明可以等待恰当的时间让尽量多的船只都走进照相机的视野里,你不需要考虑船只之间会互相遮挡视野的情况。
Input
第一行为T,表示输入数据组数。
下面T组数据,对于每组数据:
第一行是一个数n(1\leq n\leq 10^{4}),表示船只的数量。
接下来n行,每行四个整数
x,y,z,d(-10^{6}\leq x < y \leq 10^{6},1\leq z\leq 10^{4}),表示船只的左端点位置、右端点位置、距离河边的距离,以及航行的方向。d为-1表示向左航行,1表示向右航行。
Output
对第i组数据,输出
Case #i:
然后输出一行,仅包含一个整数,表示最多可以拍到多少完整的船只。
Sample Input
3
2
1 3 1 1
2 4 1 -1
2
1 3 1 -1
2 4 1 1
1
1 4 1 1
Sample Output
Case #1:
2
Case #2:
1
Case #3:
0
Source
2016”百度之星” - 复赛(Astar Round3)
这道题考思维呐。。。
首先对于向左走的船只,其左边且向右走的船只必定会与之相遇,那么算法大致就是枚举向左走的船只。
对于任意一条船,可以转换成能完整观察到的区间[y-z,x+z],其中y-z>x+z时这条船无论如何也不能被完整地观察到。
不过数据10^6,用离散化吧。。
最后注意一只船有两个坐标点,数组开两倍!
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<vector>#include<queue>#include<stack>#include<map>#include<set>#include<string>#include<iomanip>#include<ctime>#include<climits>#include<cctype>#include<algorithm>#ifdef WIN32#define AUTO "%I64d"#else#define AUTO "%lld"#endifusing namespace std;#define smax(x,tmp) x=max((x),(tmp))#define smin(x,tmp) x=min((x),(tmp))#define maxx(x1,x2,x3) max(max(x1,x2),x3)#define minn(x1,x2,x3) min(min(x1,x2),x3)const int INF=0x3f3f3f3f;const int maxn = 10005;struct Boat{ int x,y,dis,d; inline void read() { scanf("%d%d%d%d",&x,&y,&dis,&d); }}boat[maxn];int node[maxn<<1],maxnode;int suml[maxn<<1],sumr[maxn<<1];int n;void init(){ memset(node,0,sizeof(node)); maxnode=0; scanf("%d",&n); for(int i=1;i<=n;i++) { boat[i].read(); Boat t=boat[i]; int L=t.y-t.dis,R=t.x+t.dis; if(L>R) continue; node[++maxnode]=L,node[++maxnode]=R; } sort(node+1,node+maxnode+1); maxnode=unique(node+1,node+maxnode+1)-node-1;}int work(){ memset(suml,0,sizeof(suml)); memset(sumr,0,sizeof(sumr)); int ret=0; for(int i=1;i<=n;i++) { Boat t=boat[i]; int L=t.y-t.dis,R=t.x+t.dis; if(L>R) continue; L=lower_bound(node+1,node+maxnode+1,L)-node; R=upper_bound(node+1,node+maxnode+1,R)-node; if(~t.d) sumr[L]++,sumr[R]--; else suml[L]++,suml[R]--; } for(int i=1;i<=maxnode;i++) suml[i]+=suml[i-1],sumr[i]+=sumr[i-1]; int maxcnt=0; for(int i=1;i<=maxnode;i++) { smax(maxcnt,sumr[i]); smax(ret,maxcnt+suml[i]); } return ret;}int main(){#ifndef ONLINE_JUDGE freopen("photo.in","r",stdin); freopen("photo.out","w",stdout);#endif int T,cas=0; scanf("%d",&T); while(T--) { init(); printf("Case #%d:\n%d\n",++cas,work()); } return 0;}
- HDU 5714 拍照 [杂题] [离散化]
- HDU 5714 (离散化 树状数组)
- HDU 5714 树状数组 + 离散化
- HDU 5714 拍照
- hdu 5009 离散化
- HDU 1556 离散化
- hdu 5481 离散化
- HDU - 3634 离散化
- 【dp+离散化】hdu 4028
- hdu 5009 dp+离散化
- hdu 5124 lines(离散化)
- hdu 6012 (离散化)
- HDU 5925 离散化+dfs
- hdu 5925(离散化+BFS)
- HDU-5714-拍照(区间线段覆盖)
- HDU 1856 并查集+离散化
- HDU 1199 离散化 很阴险
- HDU-4358-树状数组+离散化
- C语言字节对齐
- 环境变量,基本语法
- LG的数学计划----EXGCD
- Codeforces Round #371 (Div. 2) E dp
- GUI
- HDU 5714 拍照 [杂题] [离散化]
- bootstrap模态框的简单使用demo
- Struts2.0学习笔记---对所有方法进行校验和对某个方法进行校验
- Linux-C基础知识学习:C语言作业-从键盘输入一行字符,统计其中有多少个字母, 数字,空格(用数组实现,gets)。
- 多线程学习篇(二)等待函数
- 前端资料收集大全
- day14 Python css边距
- Java实现冒泡排序
- Android的自动锁屏、解锁