Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力

C. Edo and Magnets

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/594/problem/C

Description

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 (Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力, Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力) (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.

Under two situations the player could score one point.

⋅1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won't get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.

⋅2. Ignoring the buoys and relying on dogfighting to get point.
If you and your opponent meet in the same position, you can try to
fight with your opponent to score one point. For the proposal of game
balance, two players are not allowed to fight before buoy #2 is touched by anybody.

There are three types of players.

Speeder:
As a player specializing in high speed movement, he/she tries to avoid
dogfighting while attempting to gain points by touching buoys.
Fighter:
As a player specializing in dogfighting, he/she always tries to fight
with the opponent to score points. Since a fighter is slower than a
speeder, it's difficult for him/her to score points by touching buoys
when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.

There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting.
Since Asuka is slower than Shion, she decides to fight with Shion for
only one time during the match. It is also assumed that if Asuka and
Shion touch the buoy in the same time, the point will be given to Asuka
and Asuka could also fight with Shion at the buoy. We assume that in
such scenario, the dogfighting must happen after the buoy is touched by
Asuka or Shion.

The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

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 Input

3 1
1 1 2 2
2 2 3 3
3 3 4 4

Sample Output

1

HINT

题意

平面上,给你n个点,然后你可以删除k个点

然后让你用一个两边平行于坐标轴的矩形,去围住这n-k个点,问这个矩形的面积,最小可以是多少

题解:

时间复杂度k^4*n

贪心一下,删除点,肯定是删除边界上的点,而不是中间的点

所以我们可以直接暴力枚举最边界上的k个点,然后暴力去做就好了……

代码

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
using namespace std;
#define maxn 100005
struct node
{
int x,y;
}p[maxn];
bool cmp1(int a,int b)
{
return p[a].x<p[b].x;
}
bool cmp2(int a,int b)
{
return p[a].x>p[b].x;
}
bool cmp3(int a,int b)
{
return p[a].y<p[b].y;
}
bool cmp4(int a,int b)
{
return p[a].y>p[b].y;
}
int pos1[maxn],pos2[maxn],pos3[maxn],pos4[maxn];
int last[maxn];
int main()
{
int n,k;scanf("%d%d",&n,&k);
for(int i=;i<n;i++)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
p[i].x = (x1+x2);
p[i].y = (y1+y2);
pos1[i]=pos2[i]=pos3[i]=pos4[i]=i;
}
sort(pos1,pos1+n,cmp1);
sort(pos2,pos2+n,cmp2);
sort(pos3,pos3+n,cmp3);
sort(pos4,pos4+n,cmp4);
int now = ;
long long ans = 1LL<<;
for(int a=;a<=k;a++)for(int b=;b<=k;b++)for(int c=;c<=k;c++)for(int d=;d<=k;d++)
{
now++;
int cnt = ;
for(int i=;i<a;i++)if(last[pos1[i]]!=now)last[pos1[i]]=now,cnt++;
for(int i=;i<b;i++)if(last[pos2[i]]!=now)last[pos2[i]]=now,cnt++;
for(int i=;i<c;i++)if(last[pos3[i]]!=now)last[pos3[i]]=now,cnt++;
for(int i=;i<d;i++)if(last[pos4[i]]!=now)last[pos4[i]]=now,cnt++;
if(cnt!=k)continue;
long long Maxx=-1LL<<,Maxy=-1LL<<,Minx=1LL<<,Miny=1LL<<;
for(int i=;i<n;i++)
{
if(last[i]!=now)
{
Maxx = max(Maxx,p[i].x*1LL);
Minx = min(Minx,p[i].x*1LL);
Maxy = max(Maxy,p[i].y*1LL);
Miny = min(Miny,p[i].y*1LL);
}
}
long long x = Maxx - Minx,y = Maxy - Miny;
x = max(x,2LL);
y = max(y,2LL);
ans = min(ans,x*y);
}
printf("%lld\n",ans/);
}
上一篇:Arduino可穿戴开发入门教程(大学霸内部资料)


下一篇:sdut 2840 Best string Orz~ (dp)