UVA___10535

The shooter is in a great problem. He is trapped in a “2D” maze with a laser gun and can use it once. The gun is very powerful and the laser ray, it emanates can traverse infinite distance in its direction. In the maze the targets are some walls (Here this is line segments). If the laser ray touches any wall or intersects it, that wall will be destroyed and the ray will advance ahead. The shooter wants to know the maximum number of walls, he can destroy with a single shot. The shooter will never stand on a wall.

Input

The input file contains 100 sets which needs to be processed. The description of each set is given below: Each set starts with a postive integer, N (1 ≤ N ≤ 500) the number of walls. In next few lines there will be 4 ∗ N integers indicating two endpoints of a wall in cartesian co-ordinate system. Next line will contain (x, y) the coordinates of the shooter. All coordinates will be in the range [-10000,10000]. Input is terminated by a case where N = 0. This case should not be processed.

Output

For each set of input print the maximum number of walls, he can destroy by a single shot with his gun in a single line.

Sample Input

3

0 0 10 0

0 1 10 1

0 2 10 2

0 -1

3

0 0 10 0

0 1 10 1

0 3 10 3

0 2

0

Sample Output

3

2

题意:

从原点开枪,枪的子弹可以穿透墙壁,给出所有墙壁的两个端点以及原点,求最多可以穿透多少墙壁(只能朝一个方向开一枪)

思路:

可以将墙与原点的关系转化为可达角度,然后就会形成一个区间,那么问题模型就变为选择一个点,求覆盖到它的最多的区间

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
#define PI acos(-1.0)
struct node
{
double r;
int type;
bool operator < (const struct node&another) const
{
if(r!=another.r) return r<another.r;
return type<another.type;
}
}event[]; struct cc
{
int x0,y0,x1,y1;
}contra[]; int x,y; double caculate(int x0,int y0)
{
if(x0==x&&y0>y) return ;
if(x0==x&&y0<y) return ;
if(x0<x&&y0==y) return ;
if(x0>x&&y0==y) return ; double acor=atan((y0-y)*1.0/(x0-x));
if(acor<) acor+=PI;
if(y0<y) return +acor*/(PI);
return acor*/PI;
} int main()
{
int n;
while(~scanf("%d",&n),n!=)
{
for(int i=;i<n;i++)
cin>>contra[i].x0>>contra[i].y0>>contra[i].x1>>contra[i].y1; cin>>x>>y; int id=;
for(int i=;i<n;i++)
{
int l=caculate(contra[i].x0,contra[i].y0);
int r=caculate(contra[i].x1,contra[i].y1);
if(l>r) swap(l,r);
if(r-l>=)
{
event[id].r=;event[id++].type=-;
event[id].r=l;event[id++].type=;
event[id].r=r;event[id++].type=-;
event[id].r=;event[id++].type=;
continue;
}
event[id].r=l;event[id++].type=-;
event[id].r=r;event[id++].type=;
}
sort(event,event+id);
int maxx=;
int cur=;
for(int i=;i<id;i++)
{
if(event[i].type==-) {cur++;maxx=max(maxx,cur);}
else cur--;
}
cout<<maxx<<endl;
}
return ;
}

最新文章

  1. 浅谈js回调函数
  2. 应用程序缓存--manifest
  3. 页面打开自动触发onlick事件
  4. 在uwp中复活常用的vb库函数
  5. Servlet小知识点
  6. 查看Linux发行版的名称和版本号
  7. js substr()与substring()的区别
  8. SQLServer-----SQLServer 2008 R2卸载
  9. 学习PHP时的一些总结(四)
  10. iOS学习笔记1--在xcode6以上的版本中不使用storyboard以及部分控件使用
  11. oracle如何连接别人的数据库,需要在本地添加一些配置
  12. Docker学习笔记 - Docker容器的日志
  13. Lua常用封装方法
  14. 动态规划经典问题Java实现
  15. iOS使用NSURLConnection发送同步和异步HTTP Request
  16. make and make bzImage
  17. 【javascript基础】之【__lookupSetter__ 跟 __lookupSetter__】
  18. Oracle中ROWNUM的使用技巧
  19. gvim 编辑器配置
  20. OC-Foundation框架

热门文章

  1. Vue Router过渡动效
  2. E20170612-sl
  3. 赋予option元素点击事件后,点击select时却触发了option事件。如何解决?
  4. [App Store Connect帮助]四、添加 App 图标、App 预览和屏幕快照(6)设置 App 预览海报帧
  5. Java经典算法之折半查找(二分法)
  6. Asp.Net 开发实战技术
  7. CodeForces - 7D Palindrome Degree
  8. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-K-Matrix Multiplication(矩阵乘法)
  9. [转]T4系列文章之3:T4语法的介绍
  10. 不讲CRUSH的Ceph教程是不完整的