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 ...
随机推荐
- Spring Ajax一个简单样例
配置不说了.要在前面helloworld的样例基础上弄. 相同在hello下新建ajax.jsp <%@ page language="java" contentType=& ...
- vue - path
//path用来处理路径问题的. 1 const from = path.join(_dirname, './appes6/js'); => d:/Users/xxchi/Desktop/ES6 ...
- SSH框架优势
SSH框架优势 1. 典型的三层构架体现MVC(模型Model,视图View和控制)思想,可以让开发人员减轻重新建立解决复杂问题方案的负担和精力.便于敏捷开发出新的需求,降低开发时间成本. 2. ...
- 微信小程序 解决 数字粗细不一 的bug
1.bug 2.原因解析 微信小程序本身字体问题 3.解决方案 设置字体 font-family: Microsoft YaHei; .
- grid 布局 属性示例
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- python机器学习-逻辑回归
1.逻辑函数 假设数据集有n个独立的特征,x1到xn为样本的n个特征.常规的回归算法的目标是拟合出一个多项式函数,使得预测值与真实值的误差最小: 而我们希望这样的f(x)能够具有很好的逻辑判断性质,最 ...
- oracle linux 6 docker 安装
docker对安装系统的内核版本有严格的要求,本文针对oracle linux 6.5进行讲解,其它系统参见: https://docs.docker.com/v1.5/installation/ 下 ...
- C语言学习笔记(四) 流程控制
流程控制 流程控制,说通俗一点就是程序代码执行的顺序.不管对于哪门语言来说,流程控制都是很重要的一部分内容: 流程控制的分类,可以分为三大类: 1.顺序 这个很好理解,顺序执行就是代码从上往下一行行的 ...
- Retrofit2和RxJava配合使用Demo
和Retrofit2单独使用有一些区别 首先,同样写个interface,这里是GitHubService.java,我们这次要实现获取官方提供的测试接口的数据 public interface Gi ...
- 283. Move Zeroes【easy】
283. Move Zeroes[easy] Given an array nums, write a function to move all 0's to the end of it while ...