ARC 73 E - Ball Coloring
E - Ball Coloring
Time limit : 2sec / Memory limit : 256MB
Score : 700 points
Problem Statement
There are N bags, each containing two white balls. The i-th box contains two balls with integers xi and yi written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
- Rmax: the maximum integer written on a ball painted in red
- Rmin: the minimum integer written on a ball painted in red
- Bmax: the maximum integer written on a ball painted in blue
- Bmin: the minimum integer written on a ball painted in blue
Find the minimum possible value of (Rmax−Rmin)×(Bmax−Bmin).
Constraints
- 1≤N≤200,000
- 1≤xi,yi≤109
Input
Input is given from Standard Input in the following format:
N
x1 y1
x2 y2
:
xN yN
Output
Print the minimum possible value.
Sample Input 1
3
1 2
3 4
5 6
Sample Output 1
15
The optimal solution is to paint the balls with x1, x2, y3 red, and paint the balls with y1, y2, x3 blue.
Sample Input 2
3
1010 10
1000 1
20 1020
Sample Output 2
380
Sample Input 3
2
1 1
1000000000 1000000000
Sample Output 3
999999998000000001
分析:考虑最大值和最小值有两种情况;
1)最大值和最小值不在同一个集合,那么最大值所在集合最小值尽可能大,最小值所在集合最大值尽可能小;
那么每组数小值放小集合,大值放大集合;
2)最大值和最小值在同一个集合,考虑另一个集合,这个集合的最大值和最小值尽可能接近;
把小值排序,依次用大值替换,维护最优解即可;反证法可以证明最优解;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000009
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=2e5+;
const int N=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
int n,m,k,t,a[maxn],b[maxn],id[maxn],ama,bma,ami=1e9,bmi=1e9,dma,dmi=1e9;
bool cmp(int x,int y){return a[x]<a[y];}
int main()
{
int i,j;
scanf("%d",&n);
rep(i,,n)
{
scanf("%d%d",&a[i],&b[i]);
if(a[i]>b[i])swap(a[i],b[i]);
id[i]=i;
ama=max(ama,a[i]);
ami=min(ami,a[i]);
bma=max(bma,b[i]);
bmi=min(bmi,b[i]);
}
ll ret=(ll)(ama-ami)*(bma-bmi);
sort(id+,id+n+,cmp);
rep(i,,n)
{
dma=max(dma,b[id[i]]);
dmi=min(dmi,b[id[i]]);
ret=min(ret,(ll)(max(dma,a[id[n]])-min(dmi,a[id[i+]]))*(bma-ami));
}
printf("%lld\n",ret);
return ;
}
ARC 73 E - Ball Coloring的更多相关文章
- 【arc073e】Ball Coloring(线段树,贪心)
[arc073e]Ball Coloring(线段树,贪心) 题面 AtCoder 洛谷 题解 大型翻车现场,菊队完美压中男神的模拟题 首先钦定全局最小值为红色,剩下的袋子按照其中较大值排序. 枚举前 ...
- Ball Coloring
6552: Ball Coloring 时间限制: 1 Sec 内存限制: 128 MB提交: 13 解决: 7[提交][状态][讨论版][命题人:admin] 题目描述 There are N ...
- ARC073E Ball Coloring
Problem AtCoder Solution 把点映射至二维平面,问题就变成了给定 \(n\) 个点,可以把点对 \(y=x\) 对称,求覆盖所有点的最小矩形面积. 可以先把所有点放到 \(y=x ...
- [AT2557] [arc073_c] Ball Coloring
题目链接 AtCoder:https://arc073.contest.atcoder.jp/tasks/arc073_c 洛谷:https://www.luogu.org/problemnew/sh ...
- AtCoder Regular Contest 073 E:Ball Coloring
题目传送门:https://arc073.contest.atcoder.jp/tasks/arc073_c 题目翻译 给你\(N\)个袋子,每个袋子里有俩白球,白球上写了数字.对于每一个袋子,你需要 ...
- AtCoder瞎做第二弹
ARC 067 F - Yakiniku Restaurants 题意 \(n\) 家饭店,\(m\) 张餐票,第 \(i\) 家和第 \(i+1\) 家饭店之间的距离是 \(A_i\) ,在第 \( ...
- AtCoder Regular Contest
一句话题解 因为上篇AGC的写的有点长……估计这篇也短不了所以放个一句话题解方便查阅啥的吧QwQ 具体的题意代码题解还是往下翻…… ARC 058 D:简单容斥计数. E:用二进制表示放的数字,然后状 ...
- 【AtCoder】ARC073
ARC 073 C - Sentou 直接线段覆盖即可 #include <bits/stdc++.h> #define fi first #define se second #defin ...
- AtCoder刷题记录
构造题都是神仙题 /kk ARC066C Addition and Subtraction Hard 首先要发现两个性质: 加号右边不会有括号:显然,有括号也可以被删去,答案不变. \(op_i\)和 ...
随机推荐
- 【HNOI 2003】 激光炸弹
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1218 [算法] 二维前缀和 [代码] #include<bits/stdc++ ...
- bzoj1023 [SHOI2008]cactus仙人掌图 & poj3567 Cactus Reloaded——求仙人掌直径
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1023 http://poj.org/problem?id=3567 仙人掌!直接模仿 ...
- Mariadb-lib
mariadb-libs-5.5.44-2.el7.centos.x86_64
- linux下打开windows txt文件中文乱码问题 (转载)
转自:http://blog.csdn.net/imyang2007/article/details/7448177 在linux操作系统下,我们有时打开在windows下的txt文件,发现在wind ...
- mysql索引的操作
一.创建和查看普通索引 这是最基本的索引类型,而且它没有唯一性之类的限制 1.创建表时创建普通索引 CREATE TABLE table_name( 属性名 数据类型, ... 属性名 数据类型, I ...
- mysql数据库存储的引擎和数据类型
一.查看支持的存储引擎 SHOW ENGINES \G; 或者 SHOW VARIABLES LIKE 'have%'; 二.安装版mysql的默认引擎是InnoDB,免安装版默认引擎是MyISAM ...
- Intellij IDEA14配置
一.下载 官网下载地址:http://www.jetbrains.com/idea/ 目前最新的版本是15,发现15注册比较麻烦,好像需要只能通过联网激活.而网上14的离线注册码一大堆,就下载了14, ...
- Laravel (5.5.33) 加载过程(二)
本次说明代码 /* |-------------------------------------------------------------------------- | Turn On The ...
- Android之Glide获取图片Path和Glide获取图片Bitmap
今天主要研究了Glide获取图片Path.Bitmap用法,相信也困扰了大家很久,我在网上也找了很久,基本没有,后来研究了下,也参考了下api文档,总结了以下几个方式: 1. 获取Bitmap: 1) ...
- 新浪云虚拟机ftp链接显示失败问题
新浪云虚拟机ftp链接显示失败问题 测试是在局域网遇到的 域名解析可以ping有字节回复 账号密码也没有错误,但是链接一直出现 连接失败 拒接连接等问题 解决办法: 其实是局域网内的问题,这 ...