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. vue 简介

    Vue.js是一套构建用户界面的渐进式框架.采用自底向上增量开发的设计.Vue的核心值关注视图层非常容易与其他库和已有的项目整合.另外,Vue完全有能力驱动采用单文件组件和Vue生态系统支持的库开发复 ...

  2. bzoj1531

    背包+倍增 直接背包跑不过去,那么我们把容量分成二进制,然后原来需要枚举c次就只用枚举log(c)次了,这样还是能组合出任意小于等于c的组合方案 #include<bits/stdc++.h&g ...

  3. linux下解压zip文件时,文件名乱码的解决(转载)

    转自:http://blog.sina.com.cn/s/blog_6261f8690101c1gx.html windows下的zip文件,在linux下解压时,经常会出现文件名乱码的情况. 主要原 ...

  4. bzoj 1598: [Usaco2008 Mar]牛跑步【A*K短路】

    A*K短路模板,详见https://blog.csdn.net/z_mendez/article/details/47057461 算法流程: 把有向图全建成反向边,跑一遍所有点到t的最短路记为dis ...

  5. Visual Studio Code 扩展工具集,记录

    编码 提高效率及校验 Auto Close Tag 自动闭合标签 Auto Rename Tag 自动更改HTML/XML标签,不需要再进行二次修改,减少50%的工作量! Path Intellise ...

  6. 离散化+BFS HDOJ 4444 Walk

    题目传送门 /* 题意:问一个点到另一个点的最少转向次数. 坐标离散化+BFS:因为数据很大,先对坐标离散化后,三维(有方向的)BFS 关键理解坐标离散化,BFS部分可参考HDOJ_1728 */ # ...

  7. ViewPager(1)FragmentPagerAdapter

    FragmentPagerAdapter 适合只有少量的pager,所有pager同时全部存在,不会有被销毁的,page过多很容易内存溢出. 1,代码 1.1 ViewPagerMain.java i ...

  8. TCP/IP与Http与socket的关系

    1 理清概念: TCP/IP是一个大的协议族(只不过TCP和IP是super star所以就这么命名了),它包括了: 应用层协议:FTP.HTTP.TELNET.SMTP.DNS(协议): 传输层协议 ...

  9. 设计模式学习之代理模式(Proxy)

    一.代理模式的初衷 不想让客户端直接访问具体实现接口,客户端不应该直接访问具体实现,一般会涉及到以下四个对象 业务接口:定义客户端访问的接口,是实现类和代理类都需要实现的 实现类:实现了业务接口,真正 ...

  10. C#和Java在语法上的差异(原创,持续更新中)

    1.switch  C#一直支持String类型 Java直到1.7才支持 2.C#里String有Length属性 Java里是Length方法 3.C#中修饰class的sealed效果与Java ...