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 ...
随机推荐
- Python 提取Twitter tweets中的元素(包括text, screen names, hashtags)
CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-1 @author: guaguastd @name: ex ...
- n皇后问题[分支限界法]
问题: 如何能够在 n×n 的国际象棋棋盘上放置八个皇后,使得任何一个皇后都无法直接吃掉其他的皇后?为了达到此目的,任两个皇后都不能处于同一条横行.纵行或斜线上. 分析: 我们可以用一串数字来表示问题 ...
- 《深入PHP:面向对象、模式与实践》(二)
第4章 高级特性 本章内容提要: 静态属性和方法:通过类而不是对象来访问数据和功能 抽象类和接口:设计和实现分离 错误处理:异常 Final类和方法:限制继承 拦截器方法:自动委托 析构方法:对象销毁 ...
- 关于Spring管理的类如何创建对象
今天项目中出现了空指针错误,其实一看这个错误我就知道是哪里错了.而且以前也总是说,没有真正的改过啊.今天把改进方法和大家共享.现在我们的项目中,大多数我们的管理方式都是交由Spring去管理,至于好处 ...
- 出现蓝屏代码0x0000007b的原因及解决办法
出现蓝屏代码0x0000007b的原因通常是硬盘的存储控制器驱动加载错误,我们可以通过对BIOS界面进行修复来解决这个问题.下面小编将详细介绍解决蓝屏代码0x0000007b的方法,一起来看看吧 导致 ...
- window.onload 、body.onload 以及 jQuery 等dom加载完成后执行脚本的区别
1.关于window.onload 和 body.onload 的区别 当我们将onload 事件写在body元素上时,真正执行的其实是window对象的onload事件.因素HTMl页面中没有win ...
- Asp.net 数据库依赖那些事
声明:本文为作者原创文章,转载请注明出处 https://www.cnblogs.com/MaMaNongNong/p/8904022.html 问题背景: 最近做一个非常简单的功能,就是使用ajax ...
- IDEA13中配置struts错误:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter +找不到java程序包 解决办法
问题一:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter解决办法 1.确保所有strut ...
- poj3254 Corn Fields 利用状态压缩求方案数;
Corn Fields 2015-11-25 13:42:33 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10658 ...
- MD5摘要(Java实现)
消息摘要算法又成散列算法,其核心在于散列函数的单向性.即通过散列函数可获得对应的散列值,但不可以通过散列值反推其原始信息. 消息摘要算法分为以下三大类: MD(Message Dige ...