zoukankan      html  css  js  c++  java
  • CodeForceS#276-B(求最大值)

    B. 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

     这道题又被玩了,用int各种超范围。。。以后要注意啦。。。

    题目很简单,CF竟然把A,B题颠倒,别有用心啊。就是让你求能把所有点放在一个正方形里,这个正方形边平行x轴y轴

    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    
    long long INF = 1E9 + 10;
    typedef long long LL;
    ///又被玩了。。。
    int main()
    {
        int n;
        LL x, y;
    
        while(scanf("%d", &n) != EOF)
        {
            LL min_x = INF, min_y = INF, max_x = -INF, max_y = -INF;
            for(int i = 0; i < n; ++i)
            {
                cin >> x >> y;
                min_x = min(min_x, x);
                min_y = min(min_y, y);
                max_y = max(max_y, y);
                max_x = max(max_x, x);
            }
            LL xx = max_x - min_x;
            LL yy = max_y - min_y;
            LL dis = (xx > yy) ? xx : yy;
            cout << dis * dis <<endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    2005年春晚冯巩和朱军那个以《艺术人生》为蓝本的小品,冯巩念的诗
    《十一种孤独》札记
    《OpenCV3编程入门》 札记
    JavaScript对浏览器的URL进行编码、解码
    Jquery对Cookie的操作
    asp.net对cookie的操作
    asp.net时间 日期(DateTime) 的格式处理
    asp.net的JSON数据进行序列化和反序列化
    jQuery自动分页打印表格(HTMLtable),可以强制换页
    asp.net将内容导出到Excel,Table表格数据(html)导出EXCEL
  • 原文地址:https://www.cnblogs.com/ya-cpp/p/4077770.html
Copyright © 2011-2022 走看看