LA4253 - Archery
来源:互联网 发布:软件开发服务 编辑:程序博客网 时间:2024/06/11 22:55
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.
In the above figure, the master can hit all targets in position B. However, he never hits all targets in positionA 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 they -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(1T30) is given in the first line of the input. Each test case starts with a line containing an integerW (2W10, 000, 000) , the width of an archer line. The next line contains an integerN (2N5, 000) , the number of target boards. The i -th line of the followingN lines contains three integers Di , Li ,Ri (1DiW, 0Li <RiW) , where1iN , Di represents the y -coordinate of the i -th target, andLi and Ri represent thex -coordinates of the leftmost point and the rightmost point of the target, respectively. Note thatDi Dj if i 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 NOYES
思路:两个靶子能同时打到的范围在x轴上有个投影,只要所有的投影有交集就可以了,在计算过程中压缩公共投影区间左端和右端,最后就是判断是否存在这个公共区间。
#include <iostream>#include <stdio.h>#include <cstring>#include <algorithm>#include <queue>#include <map>#include <cmath>using namespace std;typedef long long ll;const int MAXN = 5010;int n;double w;struct node{ double d, l, r;}g[MAXN];bool cmp(node a, node b){ return a.d > b.d;}bool check(){ double l = 0.0, r = w, ll, rr; sort(g,g+n,cmp); for(int i=1; i<n; i++) { if(g[0].r == g[i].l) { ll = g[0].r; }else{ ll = g[0].r - (g[0].r - g[i].l)*g[0].d/(g[0].d - g[i].d); } if(g[0].l == g[i].r) { rr = g[0].l; }else{ rr = g[0].l - (g[0].l - g[i].r)*g[0].d/(g[0].d - g[i].d); } //cout<<ll<<" * "<<rr<<endl; //cout<<l<<" "<<r<<endl; l = max(l, ll); r = min(r, rr); } return l - r > 1e-10;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%lf",&w); scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%lf%lf%lf",&g[i].d,&g[i].l,&g[i].r); } if(check()) printf("NO\n"); else printf("YES\n"); } return 0;}
- LA4253 - Archery
- [HNOI2012]archery
- Archery Tournament
- [HNOI 2012] 射箭 archery
- UVALive 6324 Archery
- UVALive - 4253 Archery 暴力
- UVA - 1421 Archery
- Live Archive 4253 Archery
- LA 4253 Archery -
- LA 4253 Archery
- 刷清橙OJ--A1060.Archery
- uva 1421 Archery
- Archery Tournament Gym
- UVA 1421 UVALive 4253 Archery
- LA 4253 Archery (二分)
- UVA 1421 UVAlive 4253 - Archery(二分)
- uva 1421 & uvalive 4253 Archery(二分)
- UVALive 4253 Archery(二分+atan2应用)
- CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\Framework\.。。”--“拒绝访问
- 【UIKit】-3-UIAccessibility - 元素可访问性,辅助功能
- ADNROID XML图像资源文件详细讲解(二)
- 参数可以传也可以不传的用法
- ofbiz ecommerce中文设置
- LA4253 - Archery
- [POJ 1011] Sticks DFS神剪枝
- android Graphics(四):canvas变换与操作
- 实列1
- Android基础总结——Activity生命周期、横竖屏切换和启动模式(任务栈)
- 64位CPU内存限制
- JVM内存配置详解
- 产品设置
- C++定义隐式转换函数,将类转换为内部的一个成员变量