800503 finding the greatest point on the plane |
Difficulty level: C; operating time limit: 1000ms; operating space limit: 51200KB; code length limit: 2000000B |
Question Description |
In a plane, if there are two points (x, y), (A, B), if (x, y) is dominant (a, B), this refers to the x>=a,y>=b; Graphically, A (a, b) is located in an infinite area (x, y) in the upper right corner. Given the set of n points, there must be a number of points that are not dictated by any point in the collection, which are called maxima points. Programming to find all the great points, according to the x-coordinate from small to large, the output of the maximum point coordinates. The subject: N not more than 100, and do not consider the point of the coordinates of a negative case. |
Input |
The input consists of two lines, the first line is a positive integer n, the second row contains the coordinates of n points, the coordinate values are integers, the coordinates range from 0 to 100, and no points in the input data have the same coordinates. |
Output |
Outputs all the maximum points in the order of the x-axis coordinates to the smallest size. The output format is: (X1,y1), (x2,y2),... (Xk,yk) Note: There are "," dividers between each point of the output, and no "," after the last point, with fewer outputs and multiple outputs, which will be misjudged |
Input example |
5 1 2 2 2 3 1 2 3 1 4 |
Output example |
(1,4), (2,3), (3,1) |
Other Notes |
|
|
The problem: a wonderful question ... Nest Meng by x, y to do a full order, from the top right point to scan y on the line, make full use of the monotony of the line.
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn= -+Ten, inf=-1u>>1; One structp{intx, y;BOOL operator< (ConstP&B)Const{returnx<b.x| | (x==b.x&&y<b.y);}} P[MAXN]; AInlineintRead () { - intx=0, sig=1;CharCh=GetChar (); - for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') sig=0; the for(; isdigit (ch); Ch=getchar ()) x=Ten*x+ch-'0'; - returnsig?x:-x; - } -InlinevoidWriteintx) { + if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; - intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; + for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; A } at intN; - voidinit () { -n=read (); - for(intI=0; i<n;i++){ -P[i].x=read ();p [i].y=read (); - } in return; - } to intCnt=0, ANS[MAXN]; + voidWork () { -Sort (p,p+n);intmx=-inf; the for(inti=n-1; i>=0; i--){ * if(P[I].Y>MX) mx=p[i].y,ans[cnt++]=i; $ }Panax Notoginsengprintf"(%d,%d)", p[ans[cnt-1]].x,p[ans[cnt-1]].y); - for(inti=cnt-2; i>=0; i--){ theprintf", (%d,%d)", p[ans[i]].x,p[ans[i]].y); + } A return; the } + voidprint () { - return; $ } $ intMain () {init (); work ();p rint ();return 0;}
COJN 0485 800503 Looking for the greatest point on the plane