Problem

AtCoder

Solution

把点映射至二维平面,问题就变成了给定 \(n\) 个点,可以把点对 \(y=x\) 对称,求覆盖所有点的最小矩形面积。

可以先把所有点放到 \(y=x\) 下方,那么我们每次只需要贪心地把矩形左/右边界上的点对称过去即可,用multiset维护一下。

正确性在于如果把矩形内部的点对称过去,肯定不会使得当前矩形的面积变小。

时间复杂度 \(O(n\log n)\)。

Code

#include <algorithm>
#include <cstdio>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=200010,INF=0x3f3f3f3f;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
x=0;int f=0;char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') f=1,ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
if(f) x=-x;
}
struct data{
int x,y;
bool operator < (const data &b)const{return x<b.x;}
}a[maxn];
int n,mx,mn,bmn=INF;
ll ans=1e18;
multiset<int> A,B;
int main()
{
read(n);
for(int i=1;i<=n;i++)
{
read(a[i].x);read(a[i].y);
if(a[i].x>a[i].y) swap(a[i].x,a[i].y);
getmax(mx,a[i].y);getmin(bmn,a[i].y);
A.insert(a[i].x);B.insert(a[i].y);
}
sort(a+1,a+n+1);
mn=a[1].x;
for(int i=1;i<=n;i++)
{
A.erase(A.find(a[i].x));
B.insert(a[i].x);
B.erase(B.find(a[i].y));
A.insert(a[i].y);
getmin(ans,(ll)(*A.rbegin()-*A.begin())*(*B.rbegin()-*B.begin()));
}
printf("%lld\n",ans);
return 0;
}

ARC073E Ball Coloring的更多相关文章

  1. 【arc073e】Ball Coloring(线段树,贪心)

    [arc073e]Ball Coloring(线段树,贪心) 题面 AtCoder 洛谷 题解 大型翻车现场,菊队完美压中男神的模拟题 首先钦定全局最小值为红色,剩下的袋子按照其中较大值排序. 枚举前 ...

  2. Ball Coloring

    6552: Ball Coloring 时间限制: 1 Sec  内存限制: 128 MB提交: 13  解决: 7[提交][状态][讨论版][命题人:admin] 题目描述 There are N ...

  3. ARC 73 E - Ball Coloring

    E - Ball Coloring Time limit : 2sec / Memory limit : 256MB Score : 700 points Problem Statement Ther ...

  4. [AT2557] [arc073_c] Ball Coloring

    题目链接 AtCoder:https://arc073.contest.atcoder.jp/tasks/arc073_c 洛谷:https://www.luogu.org/problemnew/sh ...

  5. AtCoder Regular Contest 073 E:Ball Coloring

    题目传送门:https://arc073.contest.atcoder.jp/tasks/arc073_c 题目翻译 给你\(N\)个袋子,每个袋子里有俩白球,白球上写了数字.对于每一个袋子,你需要 ...

  6. AtCoder刷题记录

    构造题都是神仙题 /kk ARC066C Addition and Subtraction Hard 首先要发现两个性质: 加号右边不会有括号:显然,有括号也可以被删去,答案不变. \(op_i\)和 ...

  7. AtCoder瞎做第二弹

    ARC 067 F - Yakiniku Restaurants 题意 \(n\) 家饭店,\(m\) 张餐票,第 \(i\) 家和第 \(i+1\) 家饭店之间的距离是 \(A_i\) ,在第 \( ...

  8. 【AtCoder】ARC073

    ARC 073 C - Sentou 直接线段覆盖即可 #include <bits/stdc++.h> #define fi first #define se second #defin ...

  9. AtCoder Regular Contest

    一句话题解 因为上篇AGC的写的有点长……估计这篇也短不了所以放个一句话题解方便查阅啥的吧QwQ 具体的题意代码题解还是往下翻…… ARC 058 D:简单容斥计数. E:用二进制表示放的数字,然后状 ...

随机推荐

  1. cookie属性和作用

    面试面到了cookie,自己只是还是有一点欠缺,找到一篇文章,学习一下 在chrome控制台中的resources选项卡中可以看到cookie的信息. 现在的chrome控制台已经更新了,所以要到Ap ...

  2. 阿里大鱼短信发送,放到项目中报错Java.lang.NoClassDefFoundError:com/aliyuncs/exceptions/ClientException,已解决

    由于项目中使用的短信服务发送的消息太慢,所以把采用了阿里大鱼的短信服务,花费了几个小时,通过审核,发现可以单独运行.但是,放到web项目中会报错(Java.lang.NoClassDefFoundEr ...

  3. 前端学习 --Css -- 子元素的伪类

    :first-child 寻找父元素的第一个子元素,在所有的子元素中排序: :last-child 寻找父元素的最后一个子元素,在所有的子元素中排序: :nth-child 寻找父元素中的指定位置子元 ...

  4. java Class.getSimpleName() 的用法

    Usage in android: private static final String TAG = DemoApplication.class.getSimpleName(); public cl ...

  5. 解题:USACO14MAR Sabotage

    题面 题外话:我的实数二分有什么问题=.= 仍然(我为什么要这么说)是二分答案,如何检查呢?将所有的数减去二分出来的$mid$后求和得到和$sum$,然后如果在减出来的数列中能找出一段大于$sum$的 ...

  6. JAVA中properties基本用法

    转载 源地址不详 java中的properties文件是一种配置文件,主要用于表达配置信息,文件类型为*.properties,格式为文本文件,文件的内容是格式是"键=值"的格式, ...

  7. 布隆过滤器 Bloom Filter

    使用普通集合来判断一个元素是否已存在于集合中,需要占用比较大的空间.而使用Bloom Filter 可有效节省空间. Bloom Filter 以较少的内存占用及较小的误判率达到判断元素是否存已经加入 ...

  8. poj 3294 后缀数组 多字符串中不小于 k 个字符串中的最长子串

    Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 16223   Accepted: 4763 Descr ...

  9. 洛谷 P3382 【模板】三分法

    https://www.luogu.org/problem/show?pid=3382 题目描述 如题,给出一个N次函数,保证在范围[l,r]内存在一点x,使得[l,x]上单调增,[x,r]上单调减. ...

  10. [NOI1999] 棋盘分割

    COGS 100. [NOI1999] 棋盘分割 http://www.cogs.pro/cogs/problem/problem.php?pid=100 ★★   输入文件:division.in  ...