CodeForces485B——Valuable Resources(水题)

Valuable Resources

Many 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 should 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 should 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 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 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

题目大意:

    给定一些资源点坐标,建立一个正方形且平行于坐标轴的村庄,包含所有的资源点。

解题思路:

    比上个题简单。直接做就ok。

Code:

 /*************************************************************************
> File Name: CF485B.cpp
> Author: Enumz
> Mail: 369372123@qq.com
> Created Time: 2014年11月06日 星期四 01时17分03秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<climits>
#define MAXN 100000
#define LL long long
using namespace std;
int main()
{
LL max_x,min_x,max_y,min_y;
min_x=min_y=INT_MAX;
max_x=max_y=INT_MIN;
int T;
cin>>T;
while (T--)
{
int tmpx,tmpy;
cin>>tmpx>>tmpy;
if (tmpx>max_x) max_x=tmpx;
if (tmpx<min_x) min_x=tmpx;
if (tmpy>max_y) max_y=tmpy;
if (tmpy<min_y) min_y=tmpy;
}
LL Max=max(max_y-min_y,max_x-min_x);
cout<<Max*Max<<endl;
return ;
}
上一篇:linux expect, spawn用法小记


下一篇:Jenkins小菜初次使用小记