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 ...
随机推荐
- shell学习之变量、判断、重复动作
1.1 环境以及变量的定义.赋值.展开.删除 export:将一个变量导入到环境中:export PATH=$PATH:/home. readonly 讲一个变量设置为只读模式,在shell脚本中定义 ...
- glib 文档 代码 索引 编译
./configure --prefix=/opt/glib-2.28.8 --enable-staticmakemake install linux下载 WIN32下载 代码索引 文档索引 GLib ...
- Oracle逐行累加求和
最近遇到一个比较常见的问题,每行记录需要累加求和.这些问题倒不是有多难,主要是在工作的过程中会经常遇到,特别是Oracle自带的一些函数也能够很好地解决这样一些通用的查询计算,在此记录一下. 问题描述 ...
- hibernate 单元测试 5.2
单元测试 测试 dao service action package com.kaishengit.test; import org.hibernate.Session; import com.ka ...
- HDU2084:数塔(DP)
Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大 ...
- rollback的作用
#pragma mark - 以队列的形式添加 // 以队列的形式添加数据FMDB比较常用的添加方式 // FMDB不支持多个线程同时操作,所以一般以串行的方式实现相关操作 - (IBAction)i ...
- [置顶] android AIDL 进程间通信
1.定义aidl文件 a.ITestService.aidl package com.open.aidl.service; import com.open.aidl.service.ITestServ ...
- cocos2d-html5 简易 下拉表单 控件
刚才在CH5的群里问了问 有没有大侠写过 下拉表单控件啊! 没人鸟窝 ,DZ老师表示非常伤心啊 ,于是乎 自己写一个把 共享给大家. 效果图上一个 仅仅实现了一个最最主要的控件 非常eas ...
- python求微分方程组的数值解曲线01
本人最近在写一篇关于神经网络同步的文章,其一部分模型为: x_i^{\Delta}(t)= -a_i*x_i(t)+ b_i* f(x_i(t))+ \sum\limits_{j \in\{i-1, ...
- android:music
package com.terry; import java.io.File; import java.io.FileFilter; import java.io.IOException; impor ...