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 ;
}

F - Shooter的更多相关文章

  1. Mysql_以案例为基准之查询

    查询数据操作

  2. JSBinding + SharpKit / 实战:转换 Survival Shooter

    从 asset store 下载 Survival Shooter (商店里有2个版本,一种是给Unity5用的,一个是给Unity4.6用的,我们这个实验用的是后者,版本是2.2.如果) 1 删除多 ...

  3. 在 C# 里使用 F# 的 option 变量

    在使用 C# 与 F# 混合编程的时候(通常是使用 C# 实现 GUI,F#负责数据处理),经常会遇到要判断一个 option 是 None 还是 Some.虽然 Option module 里有 i ...

  4. 如果你也会C#,那不妨了解下F#(7):面向对象编程之继承、接口和泛型

    前言 面向对象三大基本特性:封装.继承.多态.上一篇中介绍了类的定义,下面就了解下F#中继承和多态的使用吧.

  5. 如果你也会C#,那不妨了解下F#(2):数值运算和流程控制语法

    本文链接:http://www.cnblogs.com/hjklin/p/fs-for-cs-dev-2.html 一些废话 一门语言火不火,与语言本身并没太大关系,主要看语言的推广. 推广得好,用的 ...

  6. 使用F#开发ASP.NET Core应用程序

    .NET Core 里的F# 在.NET Core刚发布时,就已经添加了对F#的支持.但因为当时F#组件还不完整,而一些依赖包并没有放在Nuget上,而是社区自己放到MyGet上,所以在使用dotne ...

  7. 如果你也会C#,那不妨了解下F#(6):面向对象编程之“类”

    前言 面向对象的思想已经非常成熟,而使用C#的程序员对面向对象也是非常熟悉,所以我就不对面向对象进行介绍了,在这篇文章中将只会介绍面向对象在F#中的使用. F#是支持面向对象的函数式编程语言,所以你用 ...

  8. 如果你也会C#,那不妨了解下F#(5):模块、与C#互相调用

    F# 项目 在之前的几篇文章介绍的代码都在交互窗口(fsi.exe)里运行,但平常开发的软件程序可能含有大类类型和函数定义,代码不可能都在一个文件里.下面我们来看VS里提供的F#项目模板. F#项目模 ...

  9. 如果你也会C#,那不妨了解下F#(4):了解函数及常用函数

    函数式编程其实就是按照数学上的函数运算思想来实现计算机上的运算.虽然我们不需要深入了解数学函数的知识,但应该清楚函数式编程的基础是来自于数学. 例如数学函数\(f(x) = x^2+x\),并没有指定 ...

随机推荐

  1. LED全彩显示屏色度空间

    摘要:LED全彩显示屏.LED电子大屏幕如果要有一个良好的视觉效果,其中色度占有一席重要的位置,那么该如何让LED显示屏的色度更均匀.合理呢,下面为大家总结出以下几点,供大家参考. LED全彩显示屏. ...

  2. E20180119

    Foundation   n. 基础; 地基; 粉底; 基金(会); hybrid   n. 杂种; 杂交生成的生物体; 混合物; 混合词; adj. 混合的; 杂种的;

  3. 洛谷 P1462 通往奥格瑞玛的道路(spfa+二分搜索)(4boy)

    原题:http://www.luogu.org/problem/show?pid=1462#sub 4boy: 大意:给出n个城市,有m条路,每经过一个城市都要交钱,每经过一条道路都要扣HP,有HP上 ...

  4. OpenGL 2D模式

    // // left top 这里设置的默认是左上角 // void push_view2d(int left, int top, int width, int height) { //glPushA ...

  5. Manacher HDOJ 5371 Hotaru's problem

    题目传送门 /* 题意:求形如(2 3 4) (4 3 2) (2 3 4)的最长长度,即两个重叠一半的回文串 Manacher:比赛看到这题还以为套个模板就行了,因为BC上有道类似的题,自己又学过M ...

  6. 记录一次mysql导入千万条测试数据过慢的问题!

    数据库在没有做任何优化的情况下,使用存储过程,插入1千万条测试数据. CREATE PROCEDURE addmaxdata(IN n int) BEGIN DECLARE i INT DEFAULT ...

  7. 国内使用pip / pip with GFW / pip 镜像

    sudo pip install -i https://pypi.doubanio.com/simple/ YOUR_PACKAGE_NAME --trusted-host pypi.doubanio ...

  8. 《编写可维护的Javascript》学习总结

    第一部分 一.基本规范 1.缩进:一般以四个空格为一个缩进. 2.语句结尾:最好加上分号,因为虽然“自动分号插入(ASI)”机制在没有分号的位置会插入分号,但是ASI规则复杂而且会有特殊情况发生 // ...

  9. 基本的查询流【MSSQL】

    4个DML(Data Manipulation Language)命令 SELECT INSERT UPDATE DELETE 查询语法有一个特有的固定顺序 SELECT - FROM - WHERE ...

  10. Spinner实现列表下拉功能

    public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener { ...