[HDU] [1859] Minimum Rectangle

Problem Description

Loading...

Problem Analysis

Since the premise is that the sides of the rectangular box are parallel to the x and y axes respectively
so for each x y we only need to update minx miny maxx maxy accordingly
and we can get the coordinates of the four points

Note that
first, the input format is very unusual, so the program logic needs to be handled properly
second, when initializing, note that max should be -99999999
because point coordinates can be negative

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<stdio.h>
int main() {
	int n,m;
	bool start=false;
	int maxx=0,maxy=0,minx=99999999,miny=99999999;
	while(1) {
		scanf("%d %d",&n,&m);
		if(!n&&!m&&start==false)
			break;
		else {
			if(!n&&!m) {
				printf("%d %d %d %d\n",minx,miny,maxx,maxy);
				maxx=-99999999,maxy=-99999999,minx=99999999,miny=99999999;
				start=false;
			} else {
				start=true;
				if(minx>n)
					minx=n;
				if(miny>m)
					miny=m;
				if(maxx<n)
					maxx=n;
				if(maxy<m)
					maxy=m;
			}
		}
	}
	return 0;
}

Problem address:HDU 1859 Minimum Rectangle

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...