LA 4253 Archery (二分)

185 篇文章 0 订阅
116 篇文章 0 订阅

Korea's reputation in archery is well known because the Korean archery teams have been sweeping almost all gold, silver, and bronze medals in the Olympic Games.

An archery game ICPC supported by NEXON (one of Korea's leading publishers of online contents) will be held in Korea. As a ceremonial event of the game, a famous master of archery will shoot an arrow to hit through all target boards made of paper. Because an arrow flies along a straight line, it depends on his position of the archer line whether or not he hits all targets.

The figure below shows an example of the complete view of a game field from the sky. Every target is represented by a line segment parallel to the archer line. Imagine the coordinate system of which the origin is the leftmost point of the archer line and the archer line is located on the positive x -axis.

\epsfbox{p4253.eps}

In the above figure, the master can hit all targets in position B. However, he never hits all targets in position A because any ray from A intersects at most 3 targets.

Given the width of the archer line and the target locations, write a program for determining if there exists a position at which the master can hit all targets. You may assume that the y -coordinates of all targets are different. Note that if an arrow passes through an end point of a target, it is considered to hit that target.

Input 

Your program is to read from standard input. The input consists of T test cases. The number of test cases T(1$ \le$T$ \le$30) is given in the first line of the input. Each test case starts with a line containing an integerW (2$ \le$W$ \le$10, 000, 000) , the width of an archer line. The next line contains an integer N (2$ \le$N$ \le$5, 000) , the number of target boards. The i -th line of the following N lines contains three integers Di , Li , Ri (1$ \le$Di$ \le$W, 0$ \le$Li < Ri$ \le$W) , where 1$ \le$i$ \le$N , Di represents the y -coordinate of the i -th target, and Li andRi represent the x -coordinates of the leftmost point and the rightmost point of the target, respectively. Note that Di $ \neq$ Dj if i $ \neq$ j .

Output 

Your program is to write to standard output. Print exactly one line for each test case. Print ``YES" if there exists a position on the archer line at which a master of archery can hit all targets, otherwise, ``NO".

The following shows sample input and output for three test cases.

Sample Input 

3 
15 
4 
10 2 7 
7 5 12 
2 7 12 
4 9 13 
6 
3 
2 1 3 
4 0 2 
5 4 6 
10 
4 
8 2 5 
4 2 5 
6 5 8 
2 5 8

Sample Output 

YES 
NO 

YES

题目大意:给你一堆靶子,每个靶子是一段区间并有自己的高度,问你能不能在给定区间内找一条直线把这些靶子全部串起来。

分析:看了网上的题解才知道做法,二分射箭的位置,然后维护一段仰角的区间,如果一个靶子在当前区间左边则向左移动,在右边则向右移动。

#include <cmath> 
#include <cstdio>
#include <iostream>
#include <algorithm>
#define max(a,b) a > b ? a:b
#define min(a,b) a > b ? b:a
#define eps 1e-9
#define pi 4*atan(1.0)
using namespace std;
int n,w,T;
struct thing 
{
	int d,l,r;
} tar[5001];
bool cmp(thing a,thing b)
{
	return a.d < b.d;
}
int check(long double x)
{
	long double L = 0,R = pi;
	for(int i = 1;i <= n;i++)
	{
		long double l = atan2(tar[i].d,tar[i].r - x);
		long double r = atan2(tar[i].d,tar[i].l - x);
		if(fabs(r - L) > eps && r < L) return -1;
		if(fabs(R - l) > eps && l > R) return 1;
		L = max(L,l);
		R = min(R,r); 
	}
	return 0;		
}
using namespace std;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&w);
		scanf("%d",&n);
		for(int i = 1;i <= n;i++) scanf("%d %d %d",&tar[i].d,&tar[i].l,&tar[i].r);
		sort(tar+1,tar+1+n,cmp);
		bool flag = false;
		long double l = 0,r = w;
		while(fabs(l - r) > eps)
		{
			long double mid = (l+r)/2;
			int num = check(mid);
			if(num == 1) l = mid;
			else 
			 if(num == -1) r = mid;
			 else 
			 {
		       	flag = true;
		       	break;
			 }
		}
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Archery是一个开源的漏洞扫描和管理平台,可以帮助用户发现和管理应用程序和系统的漏洞。下面是部署和使用Archery的步骤: 1. 安装Python和pip Archery使用Python编写,因此需要先安装Python和pip。具体安装方法可以参考Python官方文档。 2. 下载和安装Archery 可以在Archery的GitHub页面下载最新版的代码,或者使用pip安装: ``` pip install archerysec ``` 3. 配置数据库 Archery使用MySQL或PostgreSQL作为后端数据库,可以根据需要选择其中一种。在安装和配置好数据库之后,需要修改Archery的配置文件config.yaml,将数据库连接信息填写到相应的字段中。 4. 运行Archery 在修改好配置文件之后,可以使用以下命令启动Archery: ``` archerysec manage runserver ``` 该命令将启动Archery的Web界面,并监听本地的8000端口。可以通过浏览器访问http://localhost:8000/来进入Archery的主界面。 5. 添加扫描目标 在进入Archery的主界面之后,可以点击“Add Target”按钮添加扫描目标。可以选择手动输入目标的IP地址或域名,也可以导入一个IP地址或域名列表。 6. 运行漏洞扫描 添加完扫描目标之后,可以在主界面上点击“Run Scan”按钮开始漏洞扫描。Archery支持多种漏洞扫描工具,可以根据需要选择使用哪些工具进行扫描。 7. 查看漏洞报告 漏洞扫描完成后,可以在主界面上查看扫描结果。Archery将漏洞分为几个不同的等级,可以根据等级对漏洞进行筛选和排序。还可以查看每个漏洞的详细信息和建议的修复方案。 以上就是使用Archery进行漏洞扫描和管理的基本步骤。需要注意的是,Archery只是一个工具,不能完全替代人工的漏洞分析和修复工作。在使用Archery的过程中,需要结合其他安全工具和人工审查来保证应用程序和系统的安全。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值