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\)和 ...
随机推荐
- JavaScript检查是否包含某个字符
转自:http://my.oschina.net/u/1450300/blog/389325 indexOf用法: indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置.如 ...
- Scala 获取当前时间
def NowDate(): String = { val now: Date = new Date() val dateFormat: SimpleDateFormat = new SimpleDa ...
- async 函数-----------------解决异步操作隧道的亮光
之前也学过,只是没有学好,公司现在用的都是async函数 , 所以决定把它弄懂.最近看了看阮一峰的博客,做下记录. 异步I/O不就是读取一个文件吗,干嘛要搞得这么复杂?异步编程的最高境界,就是根本不用 ...
- ibatis 基类生成
using IBatisNet.Common.Utilities; using IBatisNet.DataMapper; using IBatisNet.DataMapper.Configurati ...
- Kafka详解与总结(五)
Kafka持久化 1. 概述 Kafka大量依赖文件系统去存储和缓存消息.对于硬盘有个传统的观念是硬盘总是很慢,这使很多人怀疑基于文件系统的架构能否提供优异的性能.实际上硬盘的快慢完全取决于使用它的方 ...
- Activity启动模式(GIF 动态演示)
本文首发在我的个人微信公众号:Android开发圈 引言 关于Activity的启动模式是面试高频问题,在平时开发中,作用也不小,所以还是很有必要搞懂这一块的知识.其实之前也有写过这个主题的文章,但是 ...
- Scaffold-DbContext-EFCore DB First
在使用 Scaffold-DbContext迁移数据库的时候会遇到两个问题. 一.文件已存在,其实报错很明显,增加 -force即可. 二.大小写转换,不和数据库一样了,如果要保持和数据库一致.增加 ...
- MVC系列学习(六)-Razor语法
注:本次代码加了样式,样式如下 <style> div { border: 1px solid red; margin: 10px auto; ...
- 【MySQL】二进制分发安装
操作系统:Red Hat Enterprise Linux Server release 6.5 Mysql安装包:mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz ...
- [Windows Server 2003] 还原SQL Server数据库
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:SQL Ser ...