C. Electric Charges

题目连接:

http://www.codeforces.com/contest/623/problem/C

Description

Programmer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals.

A laboratory unit is a plane with standard coordinate axes marked on it. Physicists from Moscow Institute of Physics and Technology charged the axes by large electric charges: axis X is positive and axis Y is negative.

Experienced laboratory worker marked n points with integer coordinates (xi, yi) on the plane and stopped the time. Sasha should use "atomic tweezers" to place elementary particles in these points. He has an unlimited number of electrons (negatively charged elementary particles) and protons (positively charged elementary particles). He can put either an electron or a proton at each marked point. As soon as all marked points are filled with particles, laboratory worker will turn on the time again and the particles will come in motion and after some time they will stabilize in equilibrium. The objective of the laboratory work is to arrange the particles in such a way, that the diameter of the resulting state (the maximum distance between the pairs of points of the set) is as small as possible.

Since Sasha is a programmer, he naively thinks that all the particles will simply "fall" into their projections on the corresponding axes: electrons will fall on axis X, while protons will fall on axis Y. As we are programmers too, we will consider the same model as Sasha. That is, a particle gets from point (x, y) to point (x, 0) if it is an electron and to point (0, y) if it is a proton.

As the laboratory has high background radiation and Sasha takes care of his laptop, he did not take it with him, and now he can't write a program that computes the minimum possible diameter of the resulting set. Therefore, you will have to do it for him.

Print a square of the minimum possible diameter of the set.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of points marked on the plane.

Each of the next n lines contains two integers xi and yi ( - 108 ≤ xi, yi ≤ 108) — the coordinates of the i-th point. It is guaranteed that no two points coincide.

Output

Print a single integer — the square of the minimum possible diameter of the set.

Sample Input

3
1 10
1 20
1 30

Sample Output

0

Hint

题意

平面上有n个点,坐标为(xi,yi)

然后每个点可以变成(xi,0)或者(0,yi)

都这样变换之后,问你最小的两点最大距离的平方是多少呢?

题解:

首先考虑全部扔到一维的情况,答案为min(sq(xmax-xmin),sq(ymax-ymin))sq为平方的意思。

然后我们再考虑x轴和y轴都有电子的情况

这种情况的距离最大值,显然是sq(max(abs(x)))+sq(max(abs(y)))

我们首先二分答案,然后暴力枚举放在x轴的区间的左端点,右端点显然是x轴哪些不影响答案的点

然后剩下的点都在y轴上,然后看看是否够

然后再暴力枚举右端点

然后这样就完了,这道题……

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
long long lmin[maxn],rmin[maxn];
long long lmax[maxn],rmax[maxn];
pair<long long,long long>a[maxn];
int n;
long long sq(long long x)
{return x*x;
}
bool check(long long mid)
{int r = 1;for(int l=1;l<=n;l++){if(a[l].first>0) break;while(r<n && sq(a[r+1].first-a[l].first)<=mid && abs(a[r+1].first)<=abs(a[l].first)) r++;while(abs(a[r].first)>abs(a[l].first)) r--;long long low = min(lmin[l-1],rmin[r+1]);long long high = max(lmax[l-1],rmax[r+1]);if (sq(high-low)<=mid && sq(max(abs(low),abs(high)))+sq(max(abs(a[l].first),abs(a[r].first)))<=mid) return true;}int l = n;for(int r=n;r>=1;r--){if(a[r].first<0) break;while(l>1 && sq(a[l-1].first-a[r].first)<=mid && abs(a[l-1].first)<=abs(a[r].first)) l--;while(abs(a[l].first)>abs(a[r].first)) l++;long long low = min(lmin[l-1],rmin[r+1]);long long high = max(lmax[l-1],rmax[r+1]);if (sq(high-low)<=mid && sq(max(abs(low),abs(high)))+sq(max(abs(a[l].first),abs(a[r].first)))<=mid) return true;}return false;
}
long long xmin,xmax,ymin,ymax;
int main()
{xmin=ymin=1e16,xmax=ymax=-1e16;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%lld%lld",&a[i].first,&a[i].second);xmin=min(xmin,a[i].first);xmax=max(xmax,a[i].first);ymin=min(ymin,a[i].second);ymax=max(ymax,a[i].second);}sort(a+1,a+1+n);for(int i=1;i<=n;i++){lmin[i]=min(a[i].second,lmin[i-1]);lmax[i]=max(a[i].second,lmax[i-1]);}for(int i=n;i>=1;i--){rmin[i]=min(a[i].second,rmin[i+1]);rmax[i]=max(a[i].second,rmax[i+1]);}long long l = -1,r = min(sq(xmax-xmin),sq(ymax-ymin)),ans = r;while(l<=r){long long mid = (l+r)/2;if(check(mid))ans = mid,r = mid-1;else l = mid+1;}printf("%lld\n",ans);
}

转载于:https://www.cnblogs.com/qscqesze/p/5209595.html

AIM Tech Round (Div. 1) C. Electric Charges 二分相关推荐

  1. AIM Tech Round 4 (Div. 2)ABCD

    这一场真的是血崩,a,b都被hack,还好结束前重交都过了 A:题意:找出得到k个不同的字符,所要更改的最小字符数 题解:首先如果k>字符串长度,直接impossible,然后直接记录一下不重复 ...

  2. AIM Tech Round 3 (Div. 2) A B C D

    虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...

  3. AIM Tech Round 4 (Div. 2)

    A题 分析:暴力 1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" ...

  4. CF AIM Tech Round 5 (rated, Div. 1 + Div. 2) B. Unnatural Conditions 思维 ʕ •ᴥ•ʔ

    Let s(x)s(x) be sum of digits in decimal representation of positive integer xx. Given two integers n ...

  5. AIM Tech Round 5C. Rectangles 思维

    C. Rectangles time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. Educational Codeforces Round 75 (Rated for Div. 2) D. Salary Changing 二分 + check

    传送门 文章目录 题意: 思路: 题意: 思路: 直接算不好算,考虑二分这个中位数midmidmid. 考虑如何checkcheckcheck,这个分情况来就好了: (1)mid>a[i].r( ...

  7. Codeforces Round #725 (Div. 3) G. Gift Set 二分

    传送门 文章目录 题意: 思路: 题意: 有两种物品分别有x,yx,yx,y个,每次可以从一个拿出aaa个,另一个拿出bbb个分成一组,问最多能分成多少组. 思路: 这个题有一个显然的单调性,所以二分 ...

  8. Codeforces Round #202 (Div. 1) A. Mafia 【二分】

    A. Mafia time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  9. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题

    B. Verse Pattern 题目连接: http://codeforces.com/contest/722/problem/B Description You are given a text ...

最新文章

  1. Detail-Preserving Pooling in Deep Networks
  2. Science Advances文章揭示长时记忆的神经动态表征机制
  3. 查看Oracle耗时Sql
  4. 把windows键盘作为xfce环境中的打开Applications
  5. python工程技巧_python 19个值得学习的编程技巧
  6. 深解微服务架构:从过去,到未来
  7. 【微信小程序】性能分析Trace工具
  8. html随机背景颜色,javascript实现随机生成DIV背景色
  9. HLG 1506 屠夫和狙击手【判断点在线段上+线段与圆相交】
  10. 基于虚拟机的VxWorks实验平台设计与实现(读研时的一篇论文)
  11. 电脑通过二维码打开手机链接
  12. 概率密度函数、概率函数、概率分布函数和积分等的一些概念
  13. OSPF的LSA类型 ——连载四ASBR汇总LSA
  14. 查看修改qcow2文件
  15. 事件(一)绑定与解除事件
  16. Android调用系统自带的文件管理器进行文件选择
  17. 分组密码算法与DES算法
  18. 面试必备:ArrayMap源码解析
  19. matlab一些指令
  20. Linux下最全的redis安装教程

热门文章

  1. 行走的励志君——选择和努力哪个更重要
  2. 模拟QQ登陆,并按QQ号查询QQ基本资料
  3. macbook配置java环境变量_Mac怎么配置JDK环境变量 安装JDK并配置环境变量教程
  4. discuz论坛网站更换域名的方法及步骤
  5. 服务器连接异常系统无法登录,Win10系统电脑无法登录LOL提示服务器连接异常的原因及解决方法...
  6. mybatis集成springboot的多数据源最新实现
  7. Java底层小开发的面试经历
  8. SDL入门教程(七):SDL抠色(Color Keying)
  9. html+css+javascript满屏雪花爱心520表白网站 (含音乐)520告白/七夕情人节/生日礼物/程序员表白必备
  10. Subset sum problem