Axis-Parallel Rectangle
D - Axis-Parallel Rectangle
Time limit : 2sec / Memory limit : 256MB
Problem Statement
We have N points in a two-dimensional plane.
The coordinates of the i-th point (1≤i≤N) are (xi,yi).
Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior.
Here, points on the sides of the rectangle are considered to be in the interior.
Find the minimum possible area of such a rectangle.
Constraints
- 2≤K≤N≤50
- −109≤xi,yi≤109(1≤i≤N)
- xi≠xj(1≤i<j≤N)
- yi≠yj(1≤i<j≤N)
- All input values are integers. (Added at 21:50 JST)
Input
Input is given from Standard Input in the following format:
N K
x1 y1
:
xN yN
Output
Print the minimum possible area of a rectangle that satisfies the condition.
Sample Input 1
4 4
1 4
3 3
6 2
8 1
Sample Output 1
21
One rectangle that satisfies the condition with the minimum possible area has the following vertices: (1,1), (8,1), (1,4) and (8,4).
Its area is (8−1)×(4−1)=21.
Sample Input 2
4 2
0 0
1 1
2 2
3 3
Sample Output 2
1
Sample Input 3
4 3
-1000000000 -1000000000
1000000000 1000000000
-999999999 999999999
999999999 -999999999
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 0x3f3f3f3f3f3f3f3f
#define LL long long
#define MX 55
struct Node
{
LL x, y;
bool operator < (const Node &b)const{
return x<b.x;
}
}pt[MX]; int k, n; int main()
{
scanf("%d%d",&n,&k);
for (int i=;i<=n;i++)
scanf("%lld%lld",&pt[i].x, &pt[i].y);
sort(pt+,pt++n);
LL area = INF;
for (int i=;i<=n;i++)
{
for (int j=i+;j<=n;j++)
{
LL miny = min(pt[i].y, pt[j].y);
LL maxy = max(pt[i].y, pt[j].y);
for (int q=;q<=n;q++)
{
if (pt[q].y>maxy||pt[q].y<miny) continue;
int tot = ;
for (int z=q;z<=n;z++)
{
if (pt[z].y>maxy||pt[z].y<miny) continue;
tot++;
if (tot>=k)
area = min(area, (maxy-miny)*(pt[z].x-pt[q].x));
}
}
}
}
printf("%lld\n",area);
return ;
}
Axis-Parallel Rectangle的更多相关文章
- Gym 100463D Evil DFS
Evil Time Limit: 5 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Descri ...
- Codeforces Gym 100463D Evil DFS
Evil Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Descr ...
- [Swift]LeetCode223. 矩形面积 | Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...
- HDUOJ-------2493Timer(数学 2008北京现场赛H题)
Timer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- UVALIVE 4330 Timer
Description Recently, some archaeologists discovered an ancient relic on a small island in the Pac ...
- gnulpot
gnulpot Table of Contents 1. Label position 2. coordinates 3. Symbols 4. key 4.1. key position 4.2. ...
- Codeforces Round #172 (Div. 2) C. Rectangle Puzzle 数学题几何
C. Rectangle Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/281/p ...
- Codeforces--630E--A rectangle(规律)
E - A rectangle Crawling in process... Crawling failed Time Limit:500MS Memory Limit:65536KB ...
- Rectangle Puzzle CodeForces - 281C (几何)
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of ...
- 1266 - Points in Rectangle
1266 - Points in Rectangle PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...
随机推荐
- measureChildren的工作原理
无论是在重写View还是ViewGroup的时候,尤其是ViewGrop的时候,往往不可避免的重写onMeasure方法,我们一定会调用setMeasuredDimension()将测量好的宽高值传递 ...
- RSA的密钥把JAVA格式转换成C#的格式(2)
把C#格式转换成Java:RSA的密钥把JAVA格式转换成C#的格式(1) 我已经在第一篇介绍过如何把C#格式转换成Java,现在来看看如何把Java格式转换成C#. /// <summary& ...
- ijkPlayer 集成
代码地址如下:http://www.demodashi.com/demo/11957.html 概述 ijkplayer 是一款做视频直播的框架,基于FFmpeg,支持Android和iOS.这里介绍 ...
- ADO.NET基础知识学习(SQLCOnnection&SQLCommand&SQLDataReader&SQLDataAdapter&DataSet)
通过ADO.NET技术,我们可以高效的完成客户端同数据库之间的数据访问操作,便于我们在客户端程序简便高效的访问以及获取数据库中的有用数据,同时也可以对数据库中的数据进行更新,即可以完成客户端与数据库之 ...
- 轻松学习JavaScript十四:JavaScript的RegExp对象(正則表達式)
一RegExp对象概述 RegExp对象表示正則表達式,RegExp是正則表達式的缩写.它是对字符串运行模式匹配的强大工具. RegExp 对象用于规定在文本中检索的内容. 当您检索某个文本时.能够使 ...
- redis清空部分key
redis-cli keys "test:job:*" redis-cli keys "test:job:*" |xargs redis-cli del
- sql 转 markdown
https://github.com/2liang/AutoBuildDocFromDB SQL脚本生成数据字典 http://www.jianshu.com/p/f491d0d3c503 这两个脚本 ...
- 辛星浅析Linux中的postfix
Postfix是眼下Linux下主流的邮件server,也就是MTA,主要用来实现SMTP协议,它能够兼容sendmail.而postfix也是为了改进sendmail而制作产生的. 通常来说.pos ...
- leetCode 87.Scramble String (拼凑字符串) 解题思路和方法
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- Visual Studio - 引入动态库
以VS2013为例: 1.新建项目 2.选择"Win32控制台应用程序",点确定 勾选“控制台应用程序”和“空项目”选项,点击完成,然后新建一个C文件,在文件头上右键: 3.粘贴准 ...