codeforces 595 E. Edo and Magnets
2015-11-10 17:07
274 查看
E. Edo and Magnets
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must
be positive integers.
Edo figured out how he wants to place the magnets on the refrigerator. He introduced a system of coordinates on the plane, where each magnet is represented as a rectangle with sides parallel to the coordinate axes.
Now he wants to remove no more than k magnets (he may choose to keep all of them) and attach all remaining magnets to the refrigerator
door, and the area of the door should be as small as possible. A magnet is considered to be attached to the refrigerator door if its center lies on the door or on its boundary. The relative
positions of all the remaining magnets must correspond to the plan.
Let us explain the last two sentences. Let's suppose we want to hang two magnets on the refrigerator. If the magnet in the plan has coordinates of the lower left corner (x1, y1)
and the upper right corner (x2, y2),
then its center is located at (
,
)
(may not be integers). By saying the relative position should correspond to the plan we mean that the only available operation is translation, i.e. the vector connecting the centers of two magnets in the original plan, must be equal to the vector connecting
the centers of these two magnets on the refrigerator.
The sides of the refrigerator door must also be parallel to coordinate axes.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ min(10, n - 1)) —
the number of magnets that Edo has and the maximum number of magnets Edo may not place on the refrigerator.
Next n lines describe the initial plan of placing magnets. Each line contains four integers x1, y1, x2, y2 (1 ≤ x1 < x2 ≤ 109,1 ≤ y1 < y2 ≤ 109) —
the coordinates of the lower left and upper right corners of the current magnet. The magnets can partially overlap or even fully coincide.
Output
Print a single integer — the minimum area of the door of refrigerator, which can be used to place at least n - k magnets,
preserving the relative positions.
Sample test(s)
input
output
input
output
input
output
Note
In the first test sample it is optimal to remove either the first or the third magnet. If we remove the first magnet, the centers of two others will lie at points (2.5, 2.5) and (3.5, 3.5). Thus, it is enough to buy a fridge with door width 1 and door height
1, the area of the door also equals one, correspondingly.
In the second test sample it doesn't matter which magnet to remove, the answer will not change — we need a fridge with door width 8 and door height 8.
In the third sample you cannot remove anything as k = 0.
暴力上下左右边界即可
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must
be positive integers.
Edo figured out how he wants to place the magnets on the refrigerator. He introduced a system of coordinates on the plane, where each magnet is represented as a rectangle with sides parallel to the coordinate axes.
Now he wants to remove no more than k magnets (he may choose to keep all of them) and attach all remaining magnets to the refrigerator
door, and the area of the door should be as small as possible. A magnet is considered to be attached to the refrigerator door if its center lies on the door or on its boundary. The relative
positions of all the remaining magnets must correspond to the plan.
Let us explain the last two sentences. Let's suppose we want to hang two magnets on the refrigerator. If the magnet in the plan has coordinates of the lower left corner (x1, y1)
and the upper right corner (x2, y2),
then its center is located at (
,
)
(may not be integers). By saying the relative position should correspond to the plan we mean that the only available operation is translation, i.e. the vector connecting the centers of two magnets in the original plan, must be equal to the vector connecting
the centers of these two magnets on the refrigerator.
The sides of the refrigerator door must also be parallel to coordinate axes.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ min(10, n - 1)) —
the number of magnets that Edo has and the maximum number of magnets Edo may not place on the refrigerator.
Next n lines describe the initial plan of placing magnets. Each line contains four integers x1, y1, x2, y2 (1 ≤ x1 < x2 ≤ 109,1 ≤ y1 < y2 ≤ 109) —
the coordinates of the lower left and upper right corners of the current magnet. The magnets can partially overlap or even fully coincide.
Output
Print a single integer — the minimum area of the door of refrigerator, which can be used to place at least n - k magnets,
preserving the relative positions.
Sample test(s)
input
3 1 1 1 2 2 2 2 3 3 3 3 4 4
output
1
input
4 11 1 2 2
1 9 2 10
9 9 10 10
9 1 10 2
output
64
input
3 0 1 1 2 2 1 1 1000000000 1000000000 1 3 8 12
output
249999999000000001
Note
In the first test sample it is optimal to remove either the first or the third magnet. If we remove the first magnet, the centers of two others will lie at points (2.5, 2.5) and (3.5, 3.5). Thus, it is enough to buy a fridge with door width 1 and door height
1, the area of the door also equals one, correspondingly.
In the second test sample it doesn't matter which magnet to remove, the answer will not change — we need a fridge with door width 8 and door height 8.
In the third sample you cannot remove anything as k = 0.
暴力上下左右边界即可
/*======================================================
# Author: whai
# Last modified: 2015-11-10 16:20
# Filename: e.cpp
======================================================*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define LL __int64#define PB push_back
#define P pair<int, int>
#define X first
#define Y second
const int N = 1e5 + 5;
const LL INF = 1.5 * 1e18;
struct Pt {
double x, y;
int id;
}p0
, p1;
bool cmp0(Pt a, Pt b) {
return a.x < b.x;
}
bool cmp1(Pt a, Pt b) {
return a.y < b.y;
}
bool ok(int i0, int i1, int i2, int i3, int n, int k) {
LL L0 = p0[i0].x;
LL R0 = p0[n - 1 - i1].x;
LL L1 = p1[i2].y;
LL R1 = p1[n - 1 - i3].y;
if(L0 > R0 || L1 > R1) return false;
set<int> del;
for(int i = 0; i < i0; ++i) {
del.insert(p0[i].id);
}
for(int i = n - i1; i < n; ++i) {
del.insert(p0[i].id);
}
for(int i = 0; i < i2; ++i) {
del.insert(p1[i].id);
}
for(int i = n - i3; i < n; ++i) {
del.insert(p1[i].id);
}
//cout<<i0<<' '<<i1<<' '<<i2<<' '<<i3<<' '<<del.size()<<endl;
if(del.size() <= k) return true;
else return false;
}
int main() {
int n, k;
scanf("%d%d", &n, &k);
k = min(n - 1, k);
double x[2], y[2];
for(int i = 0; i < n; ++i) {
scanf("%lf%lf%lf%lf", &x[0], &y[0], &x[1], &y[1]);
p0[i].x = p1[i].x = (x[0] + x[1]) / 2;
p0[i].y = p1[i].y = (y[0] + y[1]) / 2;
p0[i].id = p1[i].id = i;
}
sort(p0, p0 + n, cmp0);
sort(p1, p1 + n, cmp1);
LL ans = INF;
for(int i0 = 0; i0 <= k; ++i0) {
for(int i1 = 0; i1 <= k; ++i1) {
for(int i2 = 0; i2 <= k; ++i2) {
for(int i3 = 0; i3 <= k; ++i3) {
if(ok(i0, i1, i2, i3, n, k)) {
double L0 = p0[i0].x;
double R0 = p0[n - 1 - i1].x;
double L1 = p1[i2].y;
double R1 = p1[n - 1 - i3].y;
LL A = (LL)(R0 - L0 + 0.5);
LL B = (LL)(R1 - L1 + 0.5);
if(A == 0) ++A;
if(B == 0) ++B;
//cout<<L0<<' '<<R0<<' '<<L1<<' '<<R1<<endl;
ans = min(ans, A * B);
}
}
}
}
}
cout<<ans<<endl;
return 0;
}
相关文章推荐
- 程序员眼中的自己
- openSession和getCurrentSession区别
- Shader与MaskFilter
- 微软的COM中GUID和UUID、CLSID、IID .
- 我的麦本本配置
- vmware虚拟机打开没反应
- linux解压zip、bz、bz2、z、gz、tar(解包)
- Android开发之ContentProvider的简单使用
- Android shell 下 busybox,clear,tcpdump、、众多命令的移植
- 文章标题
- 内部类
- Oozie的input-events和done-flag使用
- 公司如此多怪,引全体员工竞“无奈”
- PHP操作Excel (创建Excel并写入数据)
- spring 注解 标注字段
- 前端优良习惯集锦
- yum最常用的命令
- mysql可视化监控工具mysqlmtop安装
- Windows下让Tomcat6定时重启服务的方法
- Unity3d中 Awake 和 Start的区别