Electric Charges CodeForces - 623C (二分答案)
大意: 平面上n个点每个点坐标为(x,0)或(0,y), 求任意两点距离平方最大值的最小值.
二分答案, 转化为判定最大值是否<=e, 按$x$排序后, 因为固定左端点, $y$绝对值的最大值是跟右端点单调的, 滑动一个长度平方不超过e的区间, 同时保证右端点$x$的绝对值不超过左端点, 这样对于左端点在$x$轴的情况一定是最优的, 同样再固定右端点倒序处理正半轴的情况.
#include <iostream>
#include <random>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n;
pii a[N];
int Lmin[N], Lmax[N], Rmin[N], Rmax[N]; ll sqr(ll x) {return x*x;}
ll ans = 1e18;
int chk(ll e) {
if (ans<=e) return 1;
int now = 1;
ll ans = 1e18;
REP(i,1,n) {
if (a[i].x>0) break;
while (now<n&&sqr(a[now+1].x-a[i].x)<=e&&abs(a[now+1].x)<=abs(a[i].x)) ++now;
while (abs(a[now].x)>abs(a[i].x)) --now;
int U = -1e9, D = 1e9;
if (i>1) U=max(U,Lmax[i-1]),D=min(D,Lmin[i-1]);
if (now<n) U=max(U,Rmax[now+1]),D=min(D,Rmin[now+1]);
ans = min(ans, max(sqr(U-D),max(sqr(U),sqr(D))+max(sqr(a[i].x),sqr(a[now].x))));
}
now = n;
PER(i,1,n) {
if (a[i].x<0) break;
while (now>1&&sqr(a[now-1].x-a[i].x)<=e&&abs(a[now-1].x)<=abs(a[i].x)) --now;
while (abs(a[now].x)>abs(a[i].x)) ++now;
int U = -1e9, D = 1e9;
if (i<n) U=max(U,Rmax[i+1]),D=min(D,Rmin[i+1]);
if (now>1) U=max(U,Lmax[now-1]),D=min(D,Lmin[now-1]);
ans = min(ans, max(sqr(U-D),max(sqr(U),sqr(D))+max(sqr(a[i].x),sqr(a[now].x))));
}
return ans<=e;
} int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d%d", &a[i].x,&a[i].y);
sort(a+1,a+1+n);
Lmin[1]=Lmax[1]=a[1].y;
REP(i,2,n) {
Lmin[i]=min(Lmin[i-1],a[i].y);
Lmax[i]=max(Lmax[i-1],a[i].y);
}
Rmin[n]=Rmax[n]=a[n].y;
PER(i,1,n-1) {
Rmin[i]=min(Rmin[i+1],a[i].y);
Rmax[i]=max(Rmax[i+1],a[i].y);
}
ll l = 0, r = min(sqr(Lmin[n]-Lmax[n]),sqr(a[1].x-a[n].x));
ans = r;
while (l<=r) {
if (chk(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
printf("%lld\n", ans);
}
Electric Charges CodeForces - 623C (二分答案)的更多相关文章
- Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论
n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...
- codeforces 359D 二分答案+RMQ
上学期刷过裸的RMQ模板题,不过那时候一直不理解>_< 其实RMQ很简单: 设f[i][j]表示从i开始的,长度为2^j的一段元素中的最小值or最大值 那么f[i][j]=min/max{ ...
- Codeforces 1132D(二分答案+堆)
题面 传送门 分析 二分答案,考虑如何判定 可以用贪心的方法,每次找最快没电的电脑,在没电前1单位时间给它充电 正确性显然 实现上可以维护一个堆,存储每个电脑电用完的时刻,每次从堆顶取出最小的一个给它 ...
- CodeForces 483B 二分答案
题目: B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input s ...
- CodeForces 549H | 二分答案
参考了这个博客哇 #include<cstdio> #include<algorithm> #include<cstring> #define Max(a,b,c, ...
- AIM Tech Round (Div. 1) C. Electric Charges 二分
C. Electric Charges 题目连接: http://www.codeforces.com/contest/623/problem/C Description Programmer Sas ...
- Codeforces 700A As Fast As Possible(二分答案)
[题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离 ...
- Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)
链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
随机推荐
- ORA-01652: 无法通过 128 (在表空间 HIS_TABLESPACE_TEMP 中) 扩展 temp 段
前言:采用jmeter进行压力测试,大概向oracle 添加了140W条数据. 结果系统涉及到该表的业务都异常卡.访问阿里巴巴的那个druid monitor,因为系统中集成了,查看sql监控中的sq ...
- weblogic域,管理服务器,受管服务器,集群和机器的基本知识
1.域(Domain) •它是什么? –是一个逻辑上管理的WebLogic Server组,这些组从管理上当作一个整体来操作 •域里面有什么? –服务器 –服务器集群 –机器 •规则: –同一个域中的 ...
- JVM系列3:JVM垃圾回收
1.JVM内存分配和回收 1.1 对象分配原则 在JVM系列1:内存区域中我们谈到,JVM堆中的内存划分如下: 从中可以看出堆内存分为新生代和老年代以及永久代(在JDK1.8中已经被MetaSpace ...
- 浏览器端-W3School-Browser:Window 对象
ylbtech-浏览器端-W3School-Browser:Window 对象 1.返回顶部 1. Window 对象 Window 对象 Window 对象表示浏览器中打开的窗口. 如果文档包含框架 ...
- 三步解决IDEA系列开发工具 RubyMine、IntelliJ IDEA 卡顿问题
近日有小伙伴跟我反映说自己的开发工具很卡,有没有什么解决方案?答案是当然有啦!接下来看看怎么设置! 1.打开RubyMine,或IDEA,上边工具栏选择Help,下拉选择Edit Custom VM ...
- sklearn.feature_extraction.DictVectorizer
sklearn.feature_extraction.DictVectorizer:将字典组成的列表转换成向量.(将特征与值的映射字典组成的列表转换成向量) 1. 特征矩阵行代表数据,列代表特征,0表 ...
- http详解之post 2
-----------------------post请求示例----------------#请求行POST https://re.csdn.net/csdnbi HTTP/1.1 #请求头部开始H ...
- Python学习笔记:(十二)输入输出
一.格式化输出 1.str.format()函数,格式化输出值 2.将输出值转变为字符串,可以使用repr()和str() str()函数将返回一个易读的表达式形式: repr()返回一个解释器易读的 ...
- shell历史命令
1.每分钟备份历史命令 制定计划任务:每分钟执行备份历史命令的脚本 注意:要用python写计划任务脚本,因为用shell脚本写的计划任务总是不执行 先写脚本: [root@master ~]# ca ...
- java:Mybatis框架3(二级缓存,延时和积极加载,SSI(Ibatis)集成,SSM集成)
1.二级缓存: 需要导入二级缓存jar包: mybatis03: ehcache.xml: <ehcache xmlns:xsi="http://www.w3.org/2001/XML ...