LA 4253 Archery (二分)

POJ-2949 Word Rings(SPFA DFS实现 + 环上平均权值最大) Description A word ring is a sequence of words where the last two letters of each word are the same as the first two letters of the next word (and the last two letters of the last word are the same a 阅读详情

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


基于Simulink的魔术公式轮胎动力学仿真 本篇博文主要用来记录汽车系统动力学课程的学习,仅供课程阶段参考,与实际工程应用还有较大距离。基于Simulink的魔术公式轮胎动力学仿真本实例主要有以下任务。1.建立魔术公式轮胎动力学仿真模型。2.绘制不同载荷下的轮胎纵向力—滑动率关系曲线。3.绘制不同载荷下的轮胎侧向力—侧偏角关系曲线。4.绘制不同载荷下的轮胎回正力矩—侧偏角关系曲线。提示:以下是本篇文章正文内容,下面案例可供参考。 阅读详情

相关推荐

NSGA-III相关笔记

NSGA-III目录目的区别NSGA-III的算法流程非支配排序详解归一化详解 目录 NSGA-III基于matlab的实现 参考文献 1.An Evolutionary Many-Objective Optimization Algorithm Using Reference-point Based Non-dominated Sorting Approach,Part I: Solving P...

weixin_42555400的博客 1万+

LA 4253 Archery (暴力枚举/二分答案+枚举)

LA 4253 Archery题目大意:有n个与x轴平行的线段,每条线段是一个靶子(由D,L,R表示纵坐标为D,左右端点横坐标为L,R),问在x轴的[0,W]区间上是否存在位置可以使得箭穿过所有靶子.假设箭沿直线飞行,直到无穷远处,不同靶子纵坐标不同.题目分析:解法一(O(n^2)):将靶子两两进行枚举,判断i靶子左/右端点与j靶子右/左端点在x轴上的交点形成区间与原区间取交集,若为空,无解.解法一

Continue 653

Ubuntu 系统下安装 OpenClaw(原 Clawdbot)的详细指南

Ubuntu 系统下安装 OpenClaw(原 Clawdbot)的详细指南

Science prince的博客 3539

LA 4253 Archery -

题目地址:http://vjudge.net/problem/UVALive-4253 二分x轴上的点,再用角度的区间表示能否射到 #include using namespace std; #define REP(i,a,b) for(int i=a;i<=(int)(b);++i) #define REPD(i,a,b) for(int i=a;i>=(int)(b);--i) con

BRCOCOLI的博客 395

【Unity-UGUI控件全面解析】| Canvas 画布组件详解

画布 (Canvas) 是应该容纳所有 UI 元素的区域。画布是一种带有画布组件的游戏对象,所有 UI 元素都必须是此类画布的子项。 创建新的 UI 元素(如使用菜单 GameObject > UI > Image 创建图像)时,如果场景中还没有画布,则会自动创建画布。UI 元素将创建为此画布的子项。 画布区域在 Scene 视图中显示为矩形。这样可以轻松定位 UI 元素,而无需始终显示 Game 视图。 画布 使用 EventSystem 对象来协助消息系统。

努力前行,总会成为自己心中的那道光 2万+

基于树莓派4B与NCNN的YOLOv8高效部署实战:无GPU环境下的C++加速优化全流程指南**

本文详细介绍了在树莓派4B上基于NCNN框架部署YOLOv8目标检测模型的全流程。内容包括:从PyTorch模型导出NCNN格式文件、树莓派环境配置(OpenCV和NCNN编译)、C++实现代码解析(含模型加载、推理及后处理),以及实际部署测试结果。在树莓派4B上达到约2FPS,并提供INT8量化、多线程等优化建议。该方案为无GPU设备提供了轻量化目标检测的实用部署方案,适合边缘计算场景。

FJN110的博客 926

LA 4253 Archery

这个答案具有二分性,,因为你是知道应该往左还是往右的_ (:зゝ∠) _,给做出来的神犇跪了。

QWsin的博客 805

YOLO数据集实现数据增强的方法(裁剪、平移 、旋转、改变亮度、加噪声等)

数据集样本太少怎么办?数据集优质图像不够怎么办?如何做到更好的数据预处理?一文带你学会数据增强,还可实现带标签的扩充。

路人贾的博客 4万+

uva 1421 & uvalive 4253 Archery(二分)

题目连接:uva 1421 & uvalive 4253 Archery 题目大意:有n个平行与x轴的线段,每条线段代表一个靶子。你的任务是判断是否可以站在x轴上[0,w]区间的某个位置射箭,使得箭能穿过所有靶子。 解题思路:二分人站的位置,对于每个位置,维护靶子的可以击中的角度,如果出现靶子的区间

不慌不忙、不急不躁 1902

如何学习总线技术

如何学习总线技术 以形象生动的比喻来描绘了总线技术的基本思想,指出了总线的基本分类和总线传输的基本原理,以及在学习过程中应当掌握的最基本的知识,对初学者有起到抛砖引入的作用。 0引言   如果一座只能容一个人来往的独木桥,两端的人都想要过桥,为了不拥挤、阻塞,那我们就得采取有效的办法。比如规定某段时间哪端的人过桥,另一端的人就等着该他过桥的时间段的到来,同时也还可以规定人多时要按先来后到或年

ce123的技术博客 8538

DRV8311HRRWR直流无刷(BLDC)电机驱动原理图设计

DRV8311HRRWR集成三个MOSFET 半H桥,用于驱动三相无刷直流电机(BLDC),适用于5V、9V、12V或18V直流电源轨或1S至4S电池供电应用。内部集成三个具有集成电流感测功能的电流感测放大器(CSA),可感测BLDC电机的三相电流,从而实现FOC和电流控制系统设计方案。集成保护特性:VM 欠压锁定 (UVLO)、 电荷泵欠压 (CPUV)、过流保护 (OCP)、热警告和热关断 (OTW/OTSD)、故障条件指示引脚 (nFAULT)支持 1.8V、3.3V 和 5V 逻辑输入。

zhusl6688的博客 1244

LA4253 - Archery

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 NE

5年Java后端研发,分享个人读书学习笔记。 637

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

LA 4253 Archery 二分

题意: x轴上方有若干条平行于x轴的线段 在x轴的区间\([0, \, W]\)内找一点发射一条射线,使其穿过所有线段。 问是否存在这样的点。 分析: 我们二分射线端点的坐标,将线段按纵坐标从小到大排序,维护一个可以穿过所有线段的极角区间。 如果该区间为空说明这个点不符合要求,我们可以根据扫描到的最后一条线段来调整出射点的位置。 #include <cstdio> #include &...

weixin_30877181的博客 155

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

LA 4253 Archery(二分+枚举)

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2254   这题是一道没有人通过的题。   对于这题我想到一个二分的方法,可是无论怎么调精度都通过不了。个人感觉,是精度要求的比较高,所以不容易做出这样的题。 分...

weixin_34025051的博客 163

箭术 (Archery,Seoul 2008,LA 4253)

1 #include <iostream> 2 #include <string.h> 3 #include <string> 4 #include <fstream> 5 #include <algorithm> 6 #include <stdio.h> 7 #include <...

diwei4889的博客 182

LA4253(暴力 + 枚举)

题目:LA4253 思路:不会做,思路来自于此博客 思路都是最难的,具体的代码很简答: #include &lt;iostream&gt; #include &lt;algorithm&gt; #define db double using namespace std; const int maxn = 5000 + 10; const db eps = 1e-11; int n, ...

hey 284

LA 4254 Processor (单调队列 + 二分)

题意:有n个任务,每个任务有三个参数,ri,di,wi,表示在ri di之内需要执行完工作量为wi的任务,任务可以分块执行,求执行过程中的最大速度的最小值。速度需为整数。 分析:二分判断,判断有些复杂,要用到单调队列,写的挺烂的,但是一遍过了。 #include #include #include #include #include #define MAXN 10002

WZJRJ28 1040

Ural 2038 Minimum Vertex Cover(二分图最小顶点覆盖+快速读入)

题意:给你一个二分图,让你把二分图中的点划分为三个集合:一定在最小顶点覆盖集中,一定不在,可能在。 分析:若一个匹配点和一个未匹配点之间有边,那这个匹配点一定在最小顶点覆盖集中,它的另一个匹配点一定不再其中,一个一定不再其中的点连向的所有点都一定给在最小顶点覆盖集中,我们可以就这样DFS一遍求出所有结果。 #include #include #include #include #inc

WZJRJ28 869

Hdu-5726 GCD (二分 + RMQ)

Problem Description Give you a sequence of N(N≤100,000) integers : a1,...,an(0ai≤1000,000,000). There are Q(Q≤100,000) queries. For each query l,r you have to calculate gcd(al,,al+1,...,ar)

WZJRJ28 751

Codeforces Round #352 (Div. 1) B. Robin Hood

We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are n citizens in Kekoland, each person

WZJRJ28 713

Gym 100886J Sockets(二分+贪心)

Valera has only one electrical socket in his flat. He also has m devices which require electricity to work. He's got n plug multipliers to plug the devices, the i-th plug multiplier has ai socke

WZJRJ28 706

Codeforces Round #361 (Div. 2) D. Friends and Subsequences (二分+RMQ)

Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows?

WZJRJ28 679

UVa 11627 Slalom (二分)

You are competing in a ski slalom, and you need to selectthe best skis for the race. The format of the race is that there areNpairs of left and right gates, where each right gate isW metres to the rig

WZJRJ28 659
上一篇: Codeforces Round #349 (Div. 1) B. World Tour
下一篇: Codeforces Round #258 (Div. 2) D. Count Good Substrings
RJ28
博客等级 码龄13年 23粉丝 365原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值