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\)和 ...
随机推荐
- Codeforces--618A--Slime CombiningCrawling(数学)
Slime CombiningCrawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144KB ...
- unsigned 赋值负数输出情况 & printf输出格式
%d 有符号10进制整数 %ld 长整型 %hd短整型 %i 有符号10进制整数 %o 无符号8进制整数 %u 无符号10进制整数 %x 无符号的16进制数字,并以小写abcdef表示 %X 无符号的 ...
- shell脚本-高级变量
shell脚本-高级变量 字符串变量切片 ${#var}: 返回字符串变量var的长度 ${var:offset}: 返回字符串变量var中从第offset个字符后(不包括第offset 个字符)的字 ...
- C. Unusual Product(cf)
http://codeforces.com/problemset/problem/405/C 题意: 给出一个n*n的矩阵,有q个操作,输入3时,输出A ,A等于第i行乘以第i列的对应元素的和(mod ...
- go语言Notepad++简易开发环境搭建(windows)
1.下载安装go语言:https://golang.org/dl/选择对应的平台,建议使用msi安装包,这个会帮你配置好环境变量(也许需要重启)对应的环境变量有: GOROOT - C:\Go\PAT ...
- IIS Express配置多站点同时运行
环境:Win10 Pro.Visual Studio 2015 Community.IIS Express 10 VS2015集成IIS Express,所以无需单独下载, 默认安装位置:C:\Pro ...
- Java常用类库(三) : HashSet和LinkedList特点简析
今天内容: l 浅撩HashSet集合元素不可重复的原理 l 使用LinkedList模拟栈和队列 1.浅撩HashSet集合元素不可重复的原理 我们知道HashSet是添加不了相同的元素的,其原 ...
- iOS动画——UIKit动画
iOS动画 iOS有很多动画技术,API主要分布在两个库中,一个是UIKit,另一个是CoreAnimation,先对UIKit动画做一下总结. UIKit动画 在UIKit中,很多API都可以看到a ...
- 关于python中的property
python中的property在类实例化的时候 可以把类方法变成类属性使用, 还可以用在简化赋值上 1)不用property的时候,你的类可能是这样写的 2)用propery的时候你可能会这样写,调 ...
- which
功能说明:显示命令的全路径. 参数选项: -a 默认在PATH路径中由前往后查找命令,如果查找到了,就停止匹配.使用-a选项将遍历所有PATH路径,输出所有匹配项. 参数-a把所有匹配命令路 ...