CodeForces485B -- Valuable Resources (water Question)

Source: Internet
Author: User

Valuable Resources


Compute computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. the world map uses the Cartesian coordinates. the sides of the city shocould be parallel to coordinate axes. the map contains mines with valuable resources, located at some points with integer coordinates. the sizes of mines are relatively small, I. e. they can be treated as points. the city shoshould be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. given the positions of the mines find the minimum possible area of the city.
Input
The first line of the input contains number n-the number of mines on the map (2 records ≤ limit n records ≤ limit 1000 ). each of the next n lines contains a pair of integers xi and yi-the coordinates of the corresponding mine (cost-limit 109 ≤ limit xi, cost yi ≤ limit 109 ). all points are pairwise distinct.
Output
Print the minimum area of the city that can cover all the mines with valuable resources.
Sample test (s)
Input
2
0 0
2 2
Output
4
Input
2
0 0
0 3
Output
9

Question:

Given the coordinates of some resource points, create a square village that is parallel to the coordinate axis and contain all resource points.

Solution:

Easier than the previous question. Click OK directly.

Code:

1 /************************************** * *********************************** 2> File Name: CF485B. cpp 3> Author: Enumz 4> Mail: [email protected] 5> Created Time: thursday, November 06, 2014 6 ******************************* **************************************** */7 8 # include <iostream> 9 # include <cstdio> 10 # include <cstdlib> 11 # include <string> 12 # include <cstring> 13 # include <list> 14 # include <queue> 15 # include <stack> 16 # include <map> 17 # include <set> 18 # include <algorithm> 19 # include <cmath> 20 # include <bitset> 21 # include <climits> 22 # define MAXN 10000023 # define LL long long24 using namespace std; 25 int main () 26 {27 LL max_x, min_x, max_y, min_y; 28 min_x = min_y = INT_MAX; 29 max_x = max_y = INT_MIN; 30 int T; 31 cin> T; 32 while (T --) 33 {34 int tmpx, tmpy; 35 cin> tmpx> tmpy; 36 if (tmpx> max_x) max_x = tmpx; 37 if (tmpx <min_x) min_x = tmpx; 38 if (tmpy> max_y) max_y = tmpy; 39 if (tmpy <min_y) min_y = tmpy; 40} 41 LL Max = max (max_y-min_y, max_x-min_x); 42 cout <Max * Max <endl; 43 return 0; 44}

 

CodeForces485B -- Valuable Resources (water Question)

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.