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. Linux-----Kconfig文件的简介

    内核源码树的目录下都有两个文件Kconfig和Makefile.分布到各目录的Kconfig构成了一个分布式的内核配置数据库, 每个Kconfig分别描述了所属目录源文件相关的内核配置菜单.在内核配置 ...

  2. bzoj2287

    背包+fft 既然要不选一个东西,那么我们求出前缀背包和后缀背包,每次答案就是f[i-1][w]*g[i+1][j-w] 但是这样复杂度还是n^3,跑不过,但是我们发现上面那个东西不就是个裸卷积吗,直 ...

  3. uva11149

    Consider an n-by-n matrix A. We define Ak = A ∗ A ∗ . . . ∗ A (k times). Here, ∗ denotes the usual m ...

  4. 理解C#泛型(转)

    理解C#泛型 http://www.cnblogs.com/wilber2013/p/4292240.html 泛型中的类型约束和类型推断 http://www.cnblogs.com/wilber2 ...

  5. jQuery——表单应用(2)

    多行文本框应用之高度变化 HTML: <!--表单-多行文本框应用-高度变化--> <!DOCTYPE html> <html> <head> < ...

  6. laravel 模型 $table $guarded $hidden

     首先以App\User模型为例 1.$table属性 表名,对应数据库中的表名 2.guarded)属性 guarded表示在create()方法中不能被赋值的字段 3.$hidden属性 $hid ...

  7. 303 Range Sum Query - Immutable 区域和检索 - 不可变

    给定一个数组,求出数组从索引 i 到 j  (i ≤ j) 范围内元素的总和,包含 i,  j 两点.例如:给定nums = [-2, 0, 3, -5, 2, -1],求和函数为sumRange() ...

  8. C. Coin Troubles 有依赖的背包 + 完全背包变形

    http://codeforces.com/problemset/problem/283/C 一开始的时候,看着样例不懂,为什么5 * a1 + a3不行呢?也是17啊 原来是,题目要求硬币数目a3 ...

  9. Shell脚本,简单& 强大

      摘自<码农增刊Linus与Linux>,章节:你可能不知道的Shell.   最近阅读完这本书,觉得其中有很多不错的内容,这是其中的一个Shell小甜点,拿来和大家一起分享一下,增加了 ...

  10. SQL远程连接

    一.添加远程连接EXEC sp_addlinkedserver @server = '254', @srvproduct = '',--链接服务器的 OLE DB 数据源的产品名称    @provi ...