F - Shooter
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的更多相关文章
- Mysql_以案例为基准之查询
查询数据操作
- JSBinding + SharpKit / 实战:转换 Survival Shooter
从 asset store 下载 Survival Shooter (商店里有2个版本,一种是给Unity5用的,一个是给Unity4.6用的,我们这个实验用的是后者,版本是2.2.如果) 1 删除多 ...
- 在 C# 里使用 F# 的 option 变量
在使用 C# 与 F# 混合编程的时候(通常是使用 C# 实现 GUI,F#负责数据处理),经常会遇到要判断一个 option 是 None 还是 Some.虽然 Option module 里有 i ...
- 如果你也会C#,那不妨了解下F#(7):面向对象编程之继承、接口和泛型
前言 面向对象三大基本特性:封装.继承.多态.上一篇中介绍了类的定义,下面就了解下F#中继承和多态的使用吧.
- 如果你也会C#,那不妨了解下F#(2):数值运算和流程控制语法
本文链接:http://www.cnblogs.com/hjklin/p/fs-for-cs-dev-2.html 一些废话 一门语言火不火,与语言本身并没太大关系,主要看语言的推广. 推广得好,用的 ...
- 使用F#开发ASP.NET Core应用程序
.NET Core 里的F# 在.NET Core刚发布时,就已经添加了对F#的支持.但因为当时F#组件还不完整,而一些依赖包并没有放在Nuget上,而是社区自己放到MyGet上,所以在使用dotne ...
- 如果你也会C#,那不妨了解下F#(6):面向对象编程之“类”
前言 面向对象的思想已经非常成熟,而使用C#的程序员对面向对象也是非常熟悉,所以我就不对面向对象进行介绍了,在这篇文章中将只会介绍面向对象在F#中的使用. F#是支持面向对象的函数式编程语言,所以你用 ...
- 如果你也会C#,那不妨了解下F#(5):模块、与C#互相调用
F# 项目 在之前的几篇文章介绍的代码都在交互窗口(fsi.exe)里运行,但平常开发的软件程序可能含有大类类型和函数定义,代码不可能都在一个文件里.下面我们来看VS里提供的F#项目模板. F#项目模 ...
- 如果你也会C#,那不妨了解下F#(4):了解函数及常用函数
函数式编程其实就是按照数学上的函数运算思想来实现计算机上的运算.虽然我们不需要深入了解数学函数的知识,但应该清楚函数式编程的基础是来自于数学. 例如数学函数\(f(x) = x^2+x\),并没有指定 ...
随机推荐
- [转载]android常用的API接口调用
原文地址:android常用的API接口调用作者:宋耀 显示网页: Uri uri = Uri.parse("http://www.google.com"); In ...
- bzoj Strange Way to Express Integers【excrt】
其实我没看懂题不如说根本没看--都说是excrt板子那就写个板子吧 注意开long long #include<iostream> #include<cstdio> using ...
- MvcPager 分页控件
官方教程: http://www.webdiyer.com/mvcpager
- Glide和Picassio的比较
http://blog.csdn.net/fancylovejava/article/details/44747759 对象池: Glide原理的核心是为bitmap维护一个对象池.对象池的主要目的是 ...
- 2017杭电多校第五场Rikka with Subset
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- C# 调用非托管函数
C#通过DllImport可以直接调用Windows中的一些功能.C++中已经编写好的一些方法: DllImport所在的名字空间:System.Runtime.InteropServices; Dl ...
- .net环境下程序一些未知错误的调试
由于线程冲突等一系列原因导致的处理调试方法 1.打开[事件查看器]查找出错误的地方 [控制面板]-[系统和安全]-[管理工具]-[事件查看器]
- 关于mybatis的xml文件中使用 >= 或者 <= 号报错的解决方案
当我们需要通过xml格式处理sql语句时,经常会用到< ,<=,>,>=等符号,但是很容易引起xml格式的错误,这样会导致后台将xml字符串转换为xml文档时报错,从而导致程序 ...
- (四)Mybatis总结之接口映射
前面Mybatis是直接通过Dao层与数据交互,更好的方法是Mybatis通过接口映射方式与数据交互 1.在项目中添加maven支持(即pom.xml下添加支持) <!-- 在pom.xml下配 ...
- dubbo之服务容器
服务容器是一个standalone的启动程序,因为后台服务不需要Tomcat或JBoss等Web容器的功能,如果硬要用Web容器去加载服务提供方,增加复杂性,也浪费资源. 服务容器只是一个简单的Mai ...