http://codeforces.com/problemset/problem/372/B

题意:每次给出一个区间,求里面有多少个矩形

思路:预处理,sum[i][j][k][l]代表以k,l为右下角,左上角不超过i,j有多少矩形,然后询问的时候枚举右下角就可以了

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
int n,m,T;
int sum[][][][],l[][];
char s[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
void init(){
for (int i=;i<=n;i++){
scanf("%s",s+);
for (int j=;j<=m;j++){
if (s[j]=='') continue;
if (s[j-]=='') l[i][j]=l[i][j-]+;
else l[i][j]=;
}
}
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
for (int k=i;k<=n;k++)
for (int L=j;L<=m;L++){
int tmp=<<;
int ss=;
for (int x=k;x>=i;x--){
int ll=std::min(L-j+,l[x][L]);
tmp=std::min(tmp,ll);
ss+=tmp;
}
sum[i][j][k][L]=ss;
}
}
int main(){
n=read();m=read();T=read();
init();
while (T--){
int x1=read(),y1=read(),x2=read(),y2=read(),ans=;
for (int i=x1;i<=x2;i++)
for (int j=y1;j<=y2;j++)
ans+=sum[x1][y1][i][j];
printf("%d\n",ans);
}
return ;
}

Codeforces 372B Counting Rectangles is Fun的更多相关文章

  1. Codeforces 372B Counting Rectangles is Fun:dp套dp

    题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...

  2. CF 372B Counting Rectangles is Fun [dp+数据维护]

    题意,给出一个n行m列的矩阵 里面元素是0或者1 给出q个询问 a,b,c,d 求(a,b)到(c,d)有多少个由0组成的矩形 我们定义 watermark/2/text/aHR0cDovL2Jsb2 ...

  3. Codeforces 372 B. Counting Rectangles is Fun

    $ >Codeforces \space 372 B.  Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...

  4. Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun 四维前缀和

    D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...

  5. Counting Rectangles

    Counting Rectangles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1043 Accepted: 546 De ...

  6. Project Euler 85 :Counting rectangles 数长方形

    Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...

  7. UVA - 10574 Counting Rectangles

    Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3 ...

  8. UVA 10574 - Counting Rectangles(枚举+计数)

    10574 - Counting Rectangles 题目链接 题意:给定一些点,求可以成几个边平行于坐标轴的矩形 思路:先把点按x排序,再按y排序.然后用O(n^2)的方法找出每条垂直x轴的边,保 ...

  9. Codeforces 893E - Counting Arrays

    893E - Counting Arrays 思路:质因子分解. 对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数. 相当于把k个小球分配到y个盒子里的方案数. 这个问题可以用隔板法(插 ...

随机推荐

  1. Keil伪指令

    Keil伪指令 目录 Keil伪指令... 1.     ALTNAME. 2 2.     BIT. 2 3.     BSEG.. 2 4.     CODE. 2 5.     CSEG.. 2 ...

  2. SSH自动部署(转)

    我的是windows环境,目前开发的过程中,有些项目需要一下子部署到很多的linux服务器上.写了个脚本能够自动上传文件和执行部署任务.完成这个任务需要的条件包括SSH配置和一个执行脚本. 准备 1. ...

  3. 开机启动tomcat

    windows: 成功之后在dos窗口键入 service.bat install Tomcat 输完然后按Enter键,出现如下窗口,便成功了. 进入windows服务管理,设成是自动的. #chk ...

  4. 3D打印论坛

    3D打印论坛:http://www.3done.cn http://www.03dp.com www.qjxxw.net/ http://www.3ddayin.net http://oa.zol.c ...

  5. bzoj1626[Usaco2007 Dec]Building Roads 修建道路

    Description Farmer John最近得到了一些新的农场,他想新修一些道路使得他的所有农场可以经过原有的或是新修的道路互达(也就是说,从任一个农场都可以经过一些首尾相连道路到达剩下的所有农 ...

  6. Java代码编译和执行的整个过程

    Java代码编译是由Java源码编译器来完成,流程图如下所示: Java字节码的执行是由JVM执行引擎来完成,流程图如下所示: Java代码编译和执行的整个过程包含了以下三个重要的机制: Java源码 ...

  7. 集成Dubbo服务(Spring)

    Dubbo是什么? Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点. Dubbo[]是 ...

  8. MVC 部分视图

    ASP.NET MVC 里的部分视图,相当于 Web Form 里的 User Control.我们的页面往往会有许多重用的地方,可以进行封装重用. 使用部分视图有以下优点:   1. 可以简写代码. ...

  9. php中对MYSQL操作之批量运行,与获取批量结果

    <?php //批量运行,与获取结果 //创建一个mysqli对象 $mysqli = new MySQLi("主机名","mysqlusername". ...

  10. Android 自定义UI--指南针

    有了之前的基础,下面开始实现一个简单的指南针.首先来看一下效果图, 我们可以粗略将这个指南针分为三个部分,一是圆形背景,二是刻度,三是文本.那么在写代码的时候,就可以声明三个Paint画笔来画以上三个 ...