hdu1937 Finding Seats
题意是 求最小的矩形覆盖面积内包含 k 个 空位置
枚举上下边界然后 双端队列 求 最小面积
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
const double ESP = 10e-;
const int MOD = +;
const int MAXN = +;
char graph[MAXN][MAXN];
int sum[MAXN][MAXN]; int main(){
// freopen("input.txt","r",stdin);
int R,C,K;
while(scanf("%d%d%d",&R,&C,&K)){
if(!R && !C && !K){
break;
}
for(int i = ;i < R;i++){
scanf("%s",graph[i]);
}
memset(sum,,sizeof(sum));
for(int i = ;i <= R;i++){
for(int j = ;j <= C;j++){
sum[i][j] = sum[i][j-];
sum[i][j] += sum[i-][j] - sum[i-][j-];
if(graph[i-][j-] == '.'){
sum[i][j]++;
}
}
}
int ans = R * C;
for(int x2 = R;x2 > ;x2--){
if(sum[x2][C] < K){
break;
}
for(int x1 = ;x1 <= R;x1++){
if(sum[x2][C] - sum[x1-][C] < K){
break;
}
int y1 = ;
int y2 = ;
while(y1 <= C && y2 <= C){
int cnt = sum[x2][y2]-sum[x1-][y2]-
(sum[x2][y1-] - sum[x1-][y1-]);
if(cnt < K){
y2++;
}else{
ans = min(ans,(x2-x1+)*(y2-y1+));
y1++;
if(y1 > y2){
break;
}
}
}
}
}
printf("%d\n",ans);
}
return ;
}
跟上面是类似的题,今年省赛的题 T_T
求最小矩形面积覆盖的 星星数 至少 为 k 个
就跟上面一样的题型了23333
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
const double ESP = 10e-;
const int MOD = +;
const int MAXN = +;
int graph[MAXN][MAXN];
int sum[MAXN][MAXN];
int main(){
//freopen("input.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--){
int n,k;
scanf("%d%d",&n,&k);
memset(graph,,sizeof(graph));
memset(sum,,sizeof(sum));
int stX = ,edX = ,stY = ,edY = ;
while(n--){
int a,b;
scanf("%d%d",&a,&b);
graph[a][b]++;
stX = min(a,stX);
stY = min(b,stY);
edX = max(a,edX);
edY = max(b,edY);
}
for(int i = stX;i <= edX;i++){
for(int j = stY;j <= edY;j++){
sum[i][j] = sum[i-][j] + sum[i][j-] - sum[i-][j-];
sum[i][j] += graph[i][j];
}
} int ans = (edX-stX+)*(edY-stY+);
for(int x2 = edX;x2 >= stX;x2--){
if(sum[x2][edY] < k){
break;
}
for(int x1 = stX;x1 <= edX;x1++){
if(sum[x2][edY] - sum[x1-][edY] < k){
break;
}
int y1 = stY;
int y2 = stY;
while(y1 <= edY && y2 <= edY){
int cnt = sum[x2][y2] - sum[x2][y1-]-(sum[x1-][y2]-sum[x1-][y1-]);
if(cnt < k){
y2++;
}else{
ans = min(ans,(x2-x1+)*(y2-y1+));
y1++;
if(y1 > y2){
break;
}
}
}
}
}
printf("%d\n",ans);
}
return ;
}
hdu1937 Finding Seats的更多相关文章
- HDU 1937 F - Finding Seats 枚举
F - Finding Seats Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1937 Finding Seats
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- UVa 11846 - Finding Seats Again
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- Soj题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- hdu-5992 Finding Hotels(kd-tree)
题目链接: Finding Hotels Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/ ...
- [转] Finding the Best Programmer's Font
原文 Finding the Best Programmer's Font
- LOJ Finding LCM(math)
1215 - Finding LCM Time Limit: 2 second(s) Memory Limit: 32 MB LCM is an abbreviation used for Least ...
随机推荐
- 用PHP编写Hadoop的MapReduce程序
用PHP编写Hadoop的MapReduce程序 Hadoop流 虽然Hadoop是用Java写的,但是Hadoop提供了Hadoop流,Hadoop流提供一个API, 允许用户使用任何语言编 ...
- imagemagick /tmp/magick-xxxxxxxx
问题 imagemagick在某种场景下会狂写/tmp目录,文件名形如magick-xxxxxxxx, ls -lh查看这些文件达到几百G, du -sh查看则只有几十M 被这个问题折磨了许久,大晚上 ...
- Swift入门Hello World! Swift.
苹果公司推出新的开发语言Swift,随着关于趋势,外观和OC什么是不一样的地方. 前提条件:已安装Xcode6-Beta(这个过程是不表) 1.打开Xcode6-Beta,第二选择Create a n ...
- Phalcon框架中的另类使用
不像传统的PHP框架,假设框架想被还有一个框架使用仅仅能通过rpc或是引入文件等的方式.Phalcon能够在其他框架中直接使用.这是因为Phalcon是以扩展的形式存在的,在server载入时会直接载 ...
- stm32之中断系统
概述: 提供中断控制器,用于总体管理异常,称之为“嵌套向量中断控制器:Nested Vectored Interrupt Controller (NVIC) VIC:中断管理器: NVIC:内嵌中断管 ...
- UML 顺序图
顺序图 顺序图是交互图的一种形式,它显示对象沿生命线发展,对象之间随时间的交互表示为从源生命线指向目标生命线的消息.顺序图能很好地显示那些对象与其它那些对象通信,什么消息触发了这些通信,顺序图不能很好 ...
- C++,对象的 =赋值 以及 复制构造函数赋值
1. C++默认实现了 = 号赋值:operator=只要将一个对象的内容的内容逐位复制给另外一个对象即可. 2. C++默认实现了复制构造函数:同样,只要将一个对象的内容的内容逐位复制给另外一个对象 ...
- [Swust OJ 191]--迷宫逃离(打表搜索)
题目链接:http://acm.swust.edu.cn/problem/191/ Time limit(ms): 1000 Memory limit(kb): 65535 江鸟突然想到了一个 ...
- Net::OpenSSH 模块使用
use Net::OpenSSH; my $host = "$ip"; my $user = 'root'; my $passphrase = 'uxxxxxD'; my $key ...
- CImage类的介绍与使用
CImage类的介绍与使用 程序代码下载处:http://download.csdn.net/source/2098910 下载处:http://hi.baidu.com/wangleitongxin ...