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. 我的ubuntu

    题外话:不知不觉也已经大三,最近思考了很多.在腾讯网看到了对李嘉诚的一篇专访,感触颇深. 想起来我从第一次接触ubuntu到现在也有一年了,记得第一个版本还是12.04,不过很快就换成了12.10,在 ...

  2. sql中charindex和cast结合使用

    1.CHARINDEX函数常常用来在一段字符中搜索字符或者字符串. 语法 CHARINDEX ( expression1 , expression2 [ , start_location ] ) 返回 ...

  3. myeclipse部署时An internal error occurred 错误的几种情况

    myecplise上将工程部署到应用下时,经常出现 An internal error occurred during: "Add Deployment". java.lang.N ...

  4. File中操作路径的API(转)

    这几天一直在搞Java,模板引擎系列和程序猿执业修养系列都暂停了,在Java上忙的不亦乐乎!由于对Java还不太熟悉,经历了各种纠结终于完成了任务.以下是关于Java获取当前目录的方法的备忘录. 原文 ...

  5. c++ 对象作为参数传递

    对象作为参数传递时是传值.把实参的对象赋值给形参.因此效率有点低. c++传参方式可以分为2种: 1.传值 (指针作为参数,本质上也只是把地址作为值传递了而已). 2.传引用. 所以,一切传递方式不是 ...

  6. 基于visual Studio2013解决C语言竞赛题之0305显示星期

     题目 解决代码及点评 这道题锻炼我们switch分支语句,对于条件太多时,用if符合条件分支是比较复杂的 可以使用switch代替 //5. 读入1到7之间的某个数,输出表示一星期中相应的 // ...

  7. [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)

    题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...

  8. [置顶] PHP调用move_uploaded_file()提示 failed to open stream: Permission denied(Linxux环境,以Ubuntu12.04为例)

    在使用PHP上传文件之后,我们有时候还需要移动到特定的文件夹,这时候就要调用move_uploaded_file()函数,可是会出现如下错误: Warning: move_uploaded_file( ...

  9. (Problem 21)Amicable numbers

    Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into ...

  10. java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.MethodNode(尼玛,蛋疼的错误)

    java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.MethodNode   \-[M ...