博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVALive 4221 Walk in the Park 扫描线
阅读量:6270 次
发布时间:2019-06-22

本文共 3316 字,大约阅读时间需要 11 分钟。

Walk in the Park

题目连接:

Descriptionww.co

You are responsible for inspecting the trees located in a park, to make sure they remain healthy. The location of each tree is given to you as a point in the twodimensional plane, distinct from that of every other tree. Due to recentlyreplanted grass, you are only allowed to walk through the park along a collection of paths. Each path is described by an infinite-length horizontal or vertical line in the two-dimensional plane. No tree lies on any path.

You are concerned that it may not be possible to view all the trees in the park from the paths. In particular, a tree is visible only if you can view it by standing on some path while facing in a direction perpendicular to that path; there must be no intervening tree that obstructs your view. Given the geometrical configuration of the park, please report the number of visible trees.

Input

There will be multiple input sets. For each input set, the first line will contain two integers, N and M , ( 0 < N, M$ \le$100000 ), separated by a space. N is the number of trees, and M is the number of paths.

The next N lines each contain two space-separated integers, X and Y , specifying the coordinates of a tree. X and Y may be any 32-bit integers.
The next M lines each describe a path (a vertical or horizontal line). They have the form x = K or y = K , with no spaces. K may be any 32-bit integer. x and y will be lower case.
End of the input is signified by a line with two space-separated 0's.

Output

For each input set, print a single line containing one integer, specifying the number of visible trees. There should be no blank lines between outputs.

Sample Input

6 3

-1 3
4 2
6 2
6 3
6 4
4 3
x=0
y=-1
y=5
1 2
2 3
x=5
y=5
0 0

Sample Output

5

1

Hint

题意

在二维平面上有n棵树,然后有m条道路

你能看见这棵树的定义是,这棵树存在一条到垂直于道路的线上没有任何其他的树

然后问你最多能看到多少棵树

题解:

扫描线

我们分成四个步骤跑就好了

我们从x轴正半轴看过去能看到多少棵,负半轴看过去,能看到多少,从y轴正半轴看过去,负半轴看过去

每次我们用set来记录一下vis就好了

直接暴力扫一遍

代码

#include
using namespace std;const int maxn = 100005;inline long long read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int n,m;struct node{ int x,y; int flag; int id;};node p[maxn];node l[maxn];set
S;set
Ans;bool cmp1(node a,node b){ return a.y
b.y;}bool cmp3(node a,node b){ return a.x
b.x;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0)break; memset(p,0,sizeof(p)); memset(l,0,sizeof(l)); for(int i=1;i<=n;i++) { int x,y; scanf("%d%d",&p[i].x,&p[i].y); p[i].flag = 0; p[i].id=i; } S.clear(); Ans.clear(); getchar(); for(int i=1;i<=m;i++) { char c = getchar(); getchar(); int p = read(); if(c=='x') { l[i].x=p; l[i].flag=2; } else { l[i].y=p; l[i].flag=1; } } vector
V; int first; first = 1; S.clear(); V.clear(); for(int i=1;i<=n;i++) V.push_back(p[i]); for(int i=1;i<=n;i++) if(l[i].flag==1) V.push_back(l[i]); sort(V.begin(),V.end(),cmp1); for(int i=0;i

转载地址:http://mgopa.baihongyu.com/

你可能感兴趣的文章
在iOS 8中使用UIAlertController
查看>>
第2课:通过案例对SparkStreaming 透彻理解三板斧之二:解密SparkStreaming运行机制和架构...
查看>>
IOS开发—App 在 IOS 8 的simulator运行时,定位卡死bug解决
查看>>
windows 密钥登陆 linux
查看>>
IOS 录制视频
查看>>
limit检查
查看>>
Android Things 简介
查看>>
菜鸟学Linux 第049篇笔记 DNS log, zone, view
查看>>
菜鸟学Linux 第054篇笔记 建立加密的http
查看>>
ListView 的多选模式
查看>>
宏正自动科技发表新款8/16端口双滑轨LCD KVM多电脑切换器
查看>>
解决 Missing GL version
查看>>
VS 编译链接错误集锦
查看>>
Dns域名服务器之,ACL ,转发域及子域授权的基本配置
查看>>
Android权限列表
查看>>
Linux中的网络监控命令
查看>>
360项目-07
查看>>
使用Nginx进行TCP/UDP端口转发
查看>>
读书笔记2(Effective java)
查看>>
[bat]批量替换文件内容
查看>>