CodeForceS#276-B(求最大值)
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.
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.
Print the minimum area of the city that can cover all the mines with valuable resources.
2
0 0
2 2
4
2
0 0
0 3
9
这道题又被玩了,用int各种超范围。。。以后要注意啦。。。
题目很简单,CF竟然把A,B题颠倒,别有用心啊。就是让你求能把所有点放在一个正方形里,这个正方形边平行x轴y轴
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std; long long INF = 1E9 + ;
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 = ; 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 ;
}
CodeForceS#276-B(求最大值)的更多相关文章
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- HDU 2795 Billboard(区间求最大值的位置update的操作在query里做了)
Billboard 通过这题,我知道了要活用线段树的思想,而不是拘泥于形式, 就比如这题 显然更新和查询放在一起很简单 但如果分开写 那么我觉得难度会大大增加 [题目链接]Billboard [题目类 ...
- c# 任意多个数,求最大值
c# 任意多个数,求最大值 使用parms: 正在研究中,如果有好的方案,可评论,共同进步,共同提高,谢谢!
- 【c语言】求最大值
一.我个人觉得求最大值比较简单的一种方法(当然同时求最大值和最小值时稍微改改也能行) #include <stdio.h> int main(void) { int f, i, max; ...
- zzuli求最大值
1786: 求最大值 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 134 Solved: 28SubmitStatusWeb Board Desc ...
- POJ 3264 Balanced Lineup【线段树区间查询求最大值和最小值】
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 53703 Accepted: 25237 ...
- js求最大值最小值
比较数组中数值的大小是比较常见的操作,比较大小的方法有多种,比如可以使用自带的sort()函数,代码如下: <html> <head> <meta charset=&qu ...
- java求最大值以及定义方法调用
class ArrayDome { public static void main(String[] args) { int[] arr = {-12,-51,-12,-11}; int max = ...
- 算法笔记_096:蓝桥杯练习 算法提高 求最大值(Java)
目录 1 问题描述 2 解决方案 1 问题描述 问题描述 给n个有序整数对ai bi,你需要选择一些整数对 使得所有你选定的数的ai+bi的和最大.并且要求你选定的数对的ai之和非负,bi之和非负 ...
- elasticsearch聚合案例--分组、求最大值再求最大值的均值
一.需求 A.B.C代表3个用户,第二列代表各自的得分,求A.B.C的最好成绩以及A.B.C最好成绩的均值 A 10 A 11 A 13 B 11 B 11 B 12 C 10 C 10 C 11 C ...
随机推荐
- jvm分析
是什么 jps 查看所有的jvm进程,包括进程ID,进程启动的路径等等. jstack 观察jvm中当前所有线程的运行情况和线程当前状态. 系统崩溃了?如果java程序崩溃生成core文件,j ...
- springmvc中RedirectAttributes的作用
RedirectAttributes在重定向的时候可以传参,不能跨站传参,因为参数是保存在服务器端
- IT人学习方法论(三):高效学习
一些有关“怎么学”的建议 首先需要明确方向,否则即使学习方法再高效,也不免南辕北辙,背离自己的目标.关于学习方向的讨论,请参见之前的一篇文章 .下面我来重点说一说有关“怎么学”的建议. IT技术,不是 ...
- vim、gvim加载文件慢
1. strace -f -T -o vim.strace vim 2. vim --startuptime "vim-time.txt" 3. gvim -f
- Delphi开发中各种文件扩展名代表什么文件
暂时就遇到了以下这几种,以后遇到再进行补充 .DPR Delphi Project文件,打开这个文件,就会打开所有的编程的代码文件.包含了Pascal代码 .PAS Pascal文件,Pascal单元 ...
- DIV宽度自动缓慢变化
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- C# 遍历指定目录下的所有文件及文件夹
// DirectoryInfo di = new DirectoryInfo(@"D:\Test"); // FindFile(di); static void FindFile ...
- git revert 和 git reset的区别
git revert 撤销 某次操作,此次操作之前和之后的commit和history都会保留,并且把这次撤销 作为一次最新的提交 * git revert HEAD ...
- Java Server returned HTTP response code: 401
今天写一个小功能需要通过http请求获取一些返回数据,但是在登陆时是需要进行用户名和密码的校验的.写好之后请求,返回异常Java Server returned HTTP response code: ...
- 2015最新移动App设计尺寸视觉规范【图文版】(转)
如今手机app的屏幕设计尺寸参差不齐,仿佛来到了移动界面尺寸战国时代,每家移动设备制造公司都为了迎合大众的口味,各家都在2014年大放光彩.2015年也将会是我们移动APP设计界快速发展的一年. 因为 ...