山东省第六届 ACM 省赛 Stars (尺取法)
来源:互联网 发布:网络调试助手的作用 编辑:程序博客网 时间:2024/05/18 20:10
Problem Description
There are N (1 ≤ N ≤ 400) stars in the sky. And each of them has a unique coordinate (x, y) (1 ≤ x, y ≤ N). Please calculate the minimum area of the rectangle (the edges of the rectangle must be parallel to the X, Y axes) that can cover at least K (1 ≤ K ≤ N) stars. The stars on the borders of the rectangle should not be counted, and the length of each rectangle’s edge should be an integer.
Input
Input may contain several test cases. The first line is a positive integer T (T ≤ 10), indicating the number of test cases below.
For each test cases, the first line contains two integers N, K, indicating the total number of the stars and the number of stars the rectangle should cover at least.
Each of the following N lines contains two integers x, y, indicating the coordinate of the stars.
Output
For each test case, output the answer on a single line.
Example Input
21 11 12 21 11 2
Example Output
12
题意
给出平面中 n
个整数点,求最小的至少可以覆盖 k
个点的矩形面积。
思路
把这个平面看作一个矩阵,有整数点的位置为 1
,其他位置为 0
。
求出
AC 代码
#include<bits/stdc++.h>using namespace std;#define LL long long#define INF 0x3f3f3fconst int maxn = 450;int arr[maxn][maxn];int v[maxn],n;int cal(int *l,int *r,int k){ int st,ed; st = ed = 0; for(int i=0; i<=n; i++) v[i] = r[i] - l[i]; while(ed <= n && v[ed] < k) ed++; if(ed > n)return INF; // 无法满足条件 int ret = ed; while(ed<=n) // 尺取法 { if(v[ed]-v[st] >= k) ret = min(ret,ed-st++); else ed++; } return ret;}int main(){ int T,k; scanf("%d",&T); while(T--) { scanf("%d %d",&n,&k); memset(arr,0,sizeof(arr)); for(int i=0; i<n; i++) { int x,y; scanf("%d %d",&x,&y); arr[x][y]=1; } for(int i=0; i<=n; i++) for(int j=0; j<=n; j++) // 向右推进 arr[i][j] += arr[i][j-1]; for(int i=0; i<=n; i++) for(int j=0; j<=n; j++) // 向下推进 arr[i][j] += arr[i-1][j]; int ans = n*n; for(int i=0; i<=n; i++) // 枚举两行 for(int j=i+1; j<=n; j++) ans = min(ans,(j-i)*cal(arr[i],arr[j],k)); printf("%d\n",ans); } return 0;}
- 山东省第六届 ACM 省赛 Stars (尺取法)
- 2015山东省第六届ACM省赛 Game!
- 2015山东省第六届ACM省赛 Lowest Unique Price
- 2015山东省第六届ACM省赛 Single Round Math
- sdut 3258 (第六届山东省ACM省赛H题)
- 2015山东省第六届acm省赛 C题Game!
- Balloons(山东省第一届ACM省赛)
- Emergency(山东省第一届ACM省赛)
- Shopping(山东省第一届ACM省赛)
- 山东省第四届acm省赛
- 山东省第三届ACM省赛
- 2015山东省第六届ACM省赛 Nias and Tug-of-War
- 没有什么不可能—记山东省第六届ACM程序设计竞赛(退役总结帖)
- 山东省第六届ACM竞赛 Lowest Unique Price(set+map)分析,总结
- 山东省第六届ACM大学生程序设计竞赛-Square Number(完全平方数)
- 山东省第六届ACM大学生程序设计竞赛-Single Round Math(大数除法)
- 山东省第六届ACM省赛题——Circle of Friends(强连通分量+dfs)
- "浪潮杯"第六届ACM山东省省赛山科场总结
- openstack问题记录
- ng-grid的server端排序/列筛选/翻页/loading
- 个人记录-LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal
- 练习 用脚本实现创建swap分区
- Hibernate(1)Hibernate简介和简单示例,了解Hibernate事务回滚用法
- 山东省第六届 ACM 省赛 Stars (尺取法)
- angular js 格式化日期
- 利用Java jdk(dom)解析和写入XML文件
- RCNN, fast RCNN, faster RCNN, mask RCNN
- Lua C API 的正确用法
- 构建sqlserver2008服务器
- 用闭包实现计数器
- java常用的性能优化
- CSS命名