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

20 02 2

output

4

input

20 00 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;
}

时间: 2025-01-14 11:28:06

CodeForceS#276-B(求最大值)的相关文章

求最大值和scanf函数的使用以及函数的声明

/* ============================================================================ Name : MaxNumber.c Author : lf Version : Copyright : Your copyright notice Description : 求最大值和scanf函数的使用以及函数的声明 ==========================================================

1138: 零起点学算法45——求最大值

1138: 零起点学算法45--求最大值 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 1691  Accepted: 879[Submit][Status][Web Board] Description 输入一些整数,求最大值 Input 多组测试数据 首先输入1个整数n表示测试组数 然后每行首先输入1个整数m,再输入m个整数 Output 对于每组测试数据输出1行,内容为m个整数的最大值 Sa

九度oj 题目1046:求最大值

题目1046:求最大值 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:11782 解决:4789 题目描述: 输入10个数,要求输出其中的最大值. 输入: 测试数据有多组,每组10个数. 输出: 对于每组输入,请输出其最大值(有回车). 样例输入: 10 22 23 152 65 79 85 96 32 1 样例输出: max=152 1 #include <iostream> 2 #include <vector> 3 #include <algorithm&g

&lt;28&gt;【了解】10-枚举类型介绍及定义+【掌握】11-枚举变量变量定义和使用+【掌握】13-typedef定义新的类型+【掌握】15-宏的概念及无参宏定义方法+【掌握】16-有参宏定义和使用方法+【掌握】17-应用:使用有参宏求最大值+【掌握】18-typedef和#define的区别

[了解]10-枚举类型介绍及定义 枚举类型: C语言提供了一个种类型,这种类型的变量的取值被限定在一定的范围之内了 枚举类型的定义: enum 枚举类型名{ 枚举值1,枚举值2,.... }; 举例: 定义一个变量,保存一周的第几天 enum weekday{ zhouyi,zhouer,zhousan,zhousi,zhouwu ,zhouliu,zhouri }; 定义iPhone手机的颜色 关于枚举类型元素的命名习惯 enum iColor{kIcolorWhite,kIcolorBlac

矩阵连乘 和表达式加括号求最大值

矩阵连乘核心代码1 for(int i=0;i<=n;i++) 2 m[i][j]=0; 3 for(r=1;r<n;r++) 4 for(i=1;i<=n-r;i++) 5 { 6 j=i+r; 7 m[i][j]=m[i+1][j]+p[i-1]*p[i]*p[j]; 8 s[i][j]=i; 9 for(k=i+1;k<j;k++) 10 { 11 int t=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]; 12 if(t<m[i][j]) 13

Codeforces 32E Hide-and-Seek 求2点关于镜面反射 计算几何

题目链接:点击打开链接 需要注意的是镜子在与2个人共线时是不作为障碍物,但其他情况与墙一致 #include<cstdio> #include<iostream> #include<algorithm> #include<string.h> #include<math.h> using namespace std; #define point Point const double eps = 1e-8; const double PI = aco

数组用法----求最大值、最小值和平均数

public class d { /** * @param args */ public static void main(String[] args) { // TODO 自动生成的方法存根 //数组 求最大值.最小值.平均分 int a[]={70,80,90,75,84,88}; int n; int min =100; int max = 1; for(n=0;n<6;n++) { if(max<a[n]) { max=a[n];//循环比较max和a[n]的大小 }else if(m

zzuli求最大值

1786: 求最大值 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 134  Solved: 28SubmitStatusWeb Board Description 给定n个数,a[1]到a[n],请你帮忙找出a[i] - a[j]的最大值,其中1 <= i < j <= n. Input 第一行一个数T,表示一共有T组数据(T <= 20); 每组测试数据第一行一个整数n(2 <= n <= 10 ^ 5),表示接下来

MapReduce求最大值最小值问题

import java.io.File; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapreduce.Job; import

Codeforces 10D LCIS 求最长公共上升子序列及输出这个子序列 dp

题目链接:点击打开链接 题意: 给定n长的一个序列 再给定k长的一个序列 求LCIS并输出这个子序列 如有多解输出任意解.. = - = 敲的时候听着小曲儿pre的含义还没有想清楚,万万没想到就过了... #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<mat