Sdnu 1142.Hello world! "first ACM in Shandong Province", July 21

Source: Internet
Author: User

Hello world!

Descriptionwe know that Ivan gives Saya three problems to solve (problem F), and this is the first problem.
"We need a programmer to help us for some projects. If you show us that or one of the your friends are able to program, you can pass the first hurdle.
I'll give you a problem to solve. Since This is the first hurdle, it's very simple. "
We all know this simplest program are the "Hello world!" program. This was a problem just as simple as the "Hello world!"
In a large matrix, there is some elements has been marked. For every marked element, return a marked element whose row and column is larger than the showed element ' s row and column respectively. If There is multiple solutions, return to the element whose row is the smallest; And if there is still multiple solutions, return the element whose column is the smallest. If There is no solution, return-1-1.
Saya is isn't a programmer, so she comes
Can you solve this problem to her? Inputthe input consists of several test cases.
The first line of input in each test case contains one integer N (0<n≤1000), which represents the number of marked Elem Ent.
Each of the next N lines containing, integers r and C, represent the element ' s row and column. You can assume that 0<r, c≤300. A marked element can be repeatedly showed.
The last case was followed by a line containing one zero. Outputfor each case, print the case number (1, 2 ...), and for each element ' s row and column, output the result. Your output format should imitate the sample output. Print a blank line after each test case. Sample Input
31 22 32 30
Sample Output
Case 1:2 3-1-1-1-1
still save the game. Give N and points to find the point where the horizontal ordinate is larger than the current point. If there are multiple points, the output finds the first point, which is the smallest point of the horizontal axis (the same horizontal axis is the ordinate). Initially want to use a two-dimensional array to save the point is marked, and indeed did so, found that both the space, and time, really tle. To use a more straightforward approach: sort, find.

Correct thinking: The structure of the deposit point (open two, to prevent disorderly order), sort of one, traverse, output. The code is affixed:

#include <cstdio> #include <algorithm>using namespace std;struct point{    int x, y;}; BOOL CMP (point X,point y) {    if (x.x<y.x) return true;    else if (X.X==Y.X&&X.Y<Y.Y) return true;    else return false;} int main () {    int n,kase=0;    while (scanf ("%d", &n) ==1&&n) {point        p1[1100],p2[1100];        for (int i=0;i<n;i++) {            scanf ("%d%d", &p1[i].x,&p1[i].y);            p2[i].x=p1[i].x;            p2[i].y=p1[i].y;        }        Sort (p2,p2+n,cmp);        printf ("Case%d:\n", ++kase);        for (int i=0;i<n;i++) {            int j=0;            while ((p1[i].x>=p2[j].x| | P1[I].Y>=P2[J].Y) &&j<n)                j + +;            if (j<n) printf ("%d%d\n", p2[j].x,p2[j].y);            else printf (" -1-1\n");        }        printf ("\ n");    }    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Sdnu 1142.Hello world! "first ACM in Shandong Province" July 21 "

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.