Noi question Bank 2704: Looking for the greatest point on the plane

Source: Internet
Author: User

Total time limit:
Memory Limit:
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.
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 tofour, and no points in the input data have the same coordinates.
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

This problem is actually very good processing, WR is mainly test data forgot to delete = =

Paste the code First:

1#include <stdio.h>2#include <stdlib.h>3 structpoint{4     intx;5     inty;6 };7 structPoint s[101],save[101];8 intsavenum=0;//savenum= number of current stack elements9 intcmdConst void*a,Const void*b)Ten { One     return(*(structPoint *) a). x (* (structPoint *) b). x; A } - voidReplacestructPoint a) - { thesave[savenum-2]=A; -savenum--;  - } - intMain () + { -     intn,i,j;  +scanf"%d",&n); A      for(i=0; i<n;i++) atscanf"%d%d",&s[i].x,&s[i].y); -Qsort (S,n,sizeof(structPoint ), cmd); -      for(i=0; i<n;i++) -     { -save[savenum]=S[i]; -savenum++;//Pre-entry stack in          while(((savenum-1)!=0) &&s[i].y>=save[savenum-2].Y)//I 'll take all the points I can rule . - replace (s[i]); to         if(((savenum-1)!=0) &&save[savenum-2].x==s[i].x&&save[savenum-2].Y&GT;=S[I].Y)//Exclude points equal to Y +savenum--; -     } the     if(savenum>0) *     { $printf"(%d,%d)", save[0].x,save[0].y);Panax Notoginseng          for(i=1; i<savenum;i++) -printf", (%d,%d)", save[i].x,save[i].y); the     } +     return 0; A}

The first step is to enter the point, the structure of the storage, nothing to say

Second step by X to Qsort, easy to wait for comparison and output

The third step begins by processing the points individually, as the algorithm does:

1. Put this point into the stack, update the stack of the number of elements

2. See if it's the only point on the stack.

2.1 Yes, do not operate, start processing the next point

2.2 is not the case, has been compared to the forward, meet y smaller than their own small point out of the stack (the current point assignment to the small point position)

3. It is possible to encounter the same x but y smaller points, then directly out of the stack (the number of elements of the stack-1)

Fourth Step output

Since X has been sorted from small to large, there are only two cases when a point is in the stack:

1. Greater than Y (including equals) of the previous point, this condition includes the same X

2. Same as x but Y smaller than previous point

It is not possible to have an internal dominant zone at the last point, and to handle the above two cases, the AC

Noi question Bank 2704: Looking for the greatest point on the plane

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: 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.