LA 4253 Archery (two minutes)

Source: Internet
Author: User

Korea ' s reputation in archery are well known because the Korean archery teams has been sweeping almost all gold, silver, a ND bronze medals in the Olympic games.

An archery game ICPC supported by NEXON (one of the Korea ' s leading publishers of online contents) would be held in Korea. As a ceremonial event of the game, a famous master of archery would 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 tar Gets.

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 are located On the positive x -axis.

In the above figure, the master can hits all targets in position B. However, he never hits all targets on position a because any ray from A intersects at the 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. Assume that y -coordinates of all targets is different. Note that if the arrow passes through an end point of a target, it's considered to hits that target.

Input

Your program was to read from standard input. The input consists ofTTest cases. The number of test casesT(1T)is given on the first line of the input. Each test case starts with a line containing an integerW(2W)The width of an archer line. The next line contains an integerN(2N5, $)The number of target boards. TheI-th Line of the followingNLines contains three integers Di, Li, Ri (1Diw, 0Li < Riw), where1iN , DiRepresents they-coordinate of theI-th Target, and Liand RiRepresent thex-coordinates of the leftmost point and the rightmost point of the target, respectively. Note that DI DJIf 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 hits all targets, othe Rwise, '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

The main idea: to give you a lot of targets, each target is an interval and has its own height, ask you can in a given interval to find a straight line to all these targets strung together.

Analysis: Look at the online solution to know the practice, two points archery position, and then maintain a section of elevation, if a target in the current interval left to move to the left, on the right to move to the right.

#include <cmath> #include <cstdio> #include <iostream> #include <algorithm> #define MAX (b) A > b? A:b#define min (a) 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", &AMP;TAR[I].D,&AMP;TAR[I].L,&AMP;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;el Se if (num = =-1) r =Mid       else {flag = true; Break  }}IF (flag) printf ("yes\n"), Else printf ("no\n");}}


LA 4253 Archery (two minutes)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.