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 ;
}

upc3111 star

跟上面是类似的题,今年省赛的题 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的更多相关文章

  1. HDU 1937 F - Finding Seats 枚举

    F - Finding Seats Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  2. hdu 1937 Finding Seats

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  3. UVa 11846 - Finding Seats Again

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  5. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  6. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  7. hdu-5992 Finding Hotels(kd-tree)

    题目链接: Finding Hotels Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 102400/102400 K (Java/ ...

  8. [转] Finding the Best Programmer's Font

    原文 Finding the Best Programmer's Font

  9. LOJ Finding LCM(math)

    1215 - Finding LCM Time Limit: 2 second(s) Memory Limit: 32 MB LCM is an abbreviation used for Least ...

随机推荐

  1. 第五节 Code 128 码

    128码开始於1981年推出,是一种长度可变.连续性的字母数字条码.与其他一维条码比较起来,128码是较为复杂的条码系统,而其所能支援的字元也相对地比其他一维条码来得多,又有不同的编码方式可供交互运用 ...

  2. Hadoop Hive sql语法详解

    Hadoop Hive sql语法详解 Hive 是基于Hadoop 构建的一套数据仓库分析系统,它提供了丰富的SQL查询方式来分析存储在Hadoop 分布式文件系统中的数据,可以将结构 化的数据文件 ...

  3. BZOJ 1611: [Usaco2008 Feb]Meteor Shower流星雨

    1611: [Usaco2008 Feb]Meteor Shower流星雨 Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个 ...

  4. 【C++继承与派生之二】有子对象的派生类的构造函数

    这是我今天看书刚刚看到的,觉着以前对这一块内容了解不多,所以整理一下分享给大家.首先要介绍一下子对象的概念.类的数据成员不仅可以是int.char这样的基本类型,也可以是类对象,如可以包含这样的数据成 ...

  5. 11427 - Expect the Expected(概率期望)

    11427 - Expect the Expected Some mathematical background. This problem asks you to compute the expec ...

  6. CodeForces 525C Ilya and Sticks 贪心

    题目:click here #include <iostream> #include <cstdio> #include <cstring> #include &l ...

  7. java实现随机验证码的图片

    链接地址:http://blog.sina.com.cn/s/blog_407a68fc010006qo.html 1.一共需要2个常用java文件(RandomCode.java和RandomCod ...

  8. [HDU 4842]--过河(dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4842 过河 Time Limit: 3000/1000 MS (Java/Others)    Mem ...

  9. ASP.NET MVC 5 学习教程:创建连接字符串

    原文 ASP.NET MVC 5 学习教程:创建连接字符串 起飞网 ASP.NET MVC 5 学习教程目录: 添加控制器 添加视图 修改视图和布局页 控制器传递数据给视图 添加模型 创建连接字符串 ...

  10. W3C 、HTML 、CSS 发展介绍

    一.W3C W3C 指万维网联盟(World Wide Web Consortium),创建于1994年10月,由 Tim Berners-Lee (他是html的发明人)创建. W3C开始被创建的目 ...