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. Android 使用Instrumentation进行界面的单元测试

    如果我们要对一个Activity界面上的一个按钮的点击事件进行单元测试,则可使用ActivityInstrumentationTestCase2类来进行测试. 首先我们定义一个测试类: public ...

  2. ASP.NET MVC 教程汇总

    自学MVC看这里——全网最全ASP.NET MVC 教程汇总   MVC架构已深得人心,微软也不甘落后,推出了Asp.net MVC.小编特意整理博客园乃至整个网络最具价值的MVC技术原创文章,为想要 ...

  3. 为SQL表添加全文索引范例

    --范例: --为HR_Job中的JobTitle,JobDes创建全文索引 execute sp_fulltext_catalog 'boli188', 'create' --创建全文目录,boli ...

  4. java AES加密算法

    package com.siro.tools; import javax.crypto.Cipher;import javax.crypto.spec.IvParameterSpec;import j ...

  5. POJ 2253 Difference of Clustering

    题意:给出一堆点,求从起点到终点的所有通路中相邻点的距离的最大值的最小值.(意思就是自己百度吧……) 解法:用相邻点的最大值作为权值代替路径的距离跑最短路或者最小生成树.然后我写了一个我以为是优化过的 ...

  6. [转] 使用C#开发ActiveX控件

    双魂人生 原文 使用C#开发ActiveX控件 ActiveX 是一个开放的集成平台,为开发人员.用户和 Web生产商提供了一个快速而简便的在 Internet 和 Intranet 创建程序集成和内 ...

  7. Android引用百度定位API第三方组件后导致其它.so文件无法正常加载的问题

    查看当前调试设备CPU架构的方法: adb.exe shell getprop ro.product.cpu.abi  (一般返回值为:armeabi-v7a) adb.exe shell getpr ...

  8. ASP.NET CS文件中输出JavaScript脚本的3种方法以及区别

    Response.Write 与   Page.ClientScript.RegisterStartupScript 与 Page.ClientScript.RegisterClientScriptB ...

  9. 《APUE》中的函数整理

    第1章 unix基础知识 1. char *strerror(int errnum) 该函数将errnum(就是errno值)映射为一个出错信息字符串,返回该字符串指针.声明在string.h文件中. ...

  10. linux 命令 之chomd

    chmod用于改变文件或目录的访问权限.用户用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法.  1. 文字设定法 语法:chmo ...