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

     1 /*************************************************************************
     2     > File Name: CF485B.cpp
     3     > Author: Enumz
     4     > Mail: 369372123@qq.com
     5     > Created Time: 2014年11月06日 星期四 01时17分03秒
     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 100000
    23 #define LL long long
    24 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 }
  • 相关阅读:
    读书笔记:A Philosophy of Software Design
    面向对象编程—价值万亿美元的灾难
    刚哥谈架构 (二) 我眼中的架构师
    软件质量成本神话
    API 如何选择 REST,GraphQL还是gRPC
    影响您的代码库的10个编程代码味道
    为什么要不断重构
    php导出excel表格的使用
    浅谈HTTP中Get与Post的区别
    C# 程序配置文件的操作(ConfigurationManager的使用)
  • 原文地址:https://www.cnblogs.com/Enumz/p/4078450.html
Copyright © 2020-2023  润新知