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 (, ) (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/);
}

Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力的更多相关文章

  1. Codeforces Round #330 (Div. 2) A. Vitaly and Night 暴力

    A. Vitaly and Night Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/p ...

  2. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  3. Codeforces Round #330 (Div. 1) A. Warrior and Archer 贪心 数学

    A. Warrior and Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594 ...

  4. Codeforces Round #330 (Div. 2)D. Max and Bike 二分 物理

    D. Max and Bike Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/probl ...

  5. Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理

    B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/pr ...

  6. 随笔—邀请赛前训— Codeforces Round #330 (Div. 2) B题

    题意: 这道英文题的题意稍稍有点复杂. 找长度为n的数字序列有多少种.这个序列可以分为n/k段,每段k个数字.k个数可以变成一个十进制的数Xi.要求对这每n/k个数,剔除Xi可被ai整除的情况,剔除X ...

  7. 随笔—邀请赛前训— Codeforces Round #330 (Div. 2) Vitaly and Night

    题意:给你很多对数,要么是0要么是1.不全0则ans++. 思路即题意. #include<cstdio> #include<cstring> #include<iost ...

  8. Codeforces Round #330 (Div. 2)

    C题题目出错了,unrating,2题就能有很好的名次,只能呵呵了. 水 A - Vitaly and Night /***************************************** ...

  9. Codeforces Round #330 (Div. 2) B. Pasha and Phone

    B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. 【转】mac终端安装node时候,显示“-bash: brew: command not found”,怎么解决?

    原文网址:https://segmentfault.com/q/1010000004221389/a-1020000004221408 mac终端安装node时候,显示“-bash: brew: co ...

  2. 【转】./a.out 2>&1 > outfile

    原文网址:http://www.cnblogs.com/zhaoyl/archive/2012/10/22/2733418.html APUE 3.5关于重定向有个容易迷惑人的问题: ./a.out ...

  3. Android-关于android:scrollbarStyle属性

    1. activity_maim.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android ...

  4. 关于join算法的四篇文章

    MySQL Join算法与调优白皮书(一) MySQL Join算法与调优白皮书(二) MySQL Join算法与调优白皮书(三) MySQL Join算法与调优白皮书(四) MariaDB Join ...

  5. JavaScript基础篇最全

    本章内容: 简介 定义 注释 引入文件 变量 运算符 算术运算符 比较运算符 逻辑运算符 数据类型 数字 字符串 布尔类型 数组 Math 语句 条件语句(if.switch) 循环语句(for.fo ...

  6. SDUT 3568 Rock Paper Scissors 状压统计

    就是改成把一个字符串改成三进制状压,然后分成前5位,后5位统计, 然后直接统计 f[i][j][k]代表,后5局状压为k的,前5局比和j状态比输了5局的有多少个人 复杂度是O(T*30000*25*m ...

  7. Ye.云狐J2刷机笔记 | 完美切换内部存储卡和SD卡的改法.vold.fstab

    ================================================================================Ye.完美切换内部存储卡和SD卡成功.v ...

  8. SQL遍历字符串的方法

    字符串穿越: 1.创建一个只存递增序列(1…n)的表——Temp,并将它与目标字符串所在的表Src进行笛卡尔运算.(Temp表的记录数要不小于遍历的目标字符串的长度) 2.过滤掉序列值大于串长的行. ...

  9. 限制波尔兹曼机(Restricted Boltzmann Machines)

    能量模型的概念从统计力学中得来,它描述着整个系统的某种状态,系统越有序,系统能量波动越小,趋近于平衡状态,系统越无序,能量波动越大.例如:一个孤立的物体,其内部各处的温度不尽相同,那么热就从温度较高的 ...

  10. php环境配置中各个模块在网站建设中的功能

    上一篇配置环境的时候,我们注意到,有四个模块需要配置,那么,这四个模块分别有哪些功能呢?   一.php php是我们的用来创建动态网页的强有力的脚本语言,安装过程中我们直接解压到某一个路径就好了,比 ...