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. hdu Big Number

    #include <cstdio> #include <cstring> #include <cmath> using namespace std; int mai ...

  2. NGINX的CORS--跨域访问配置

    阻止交叉源访问问题. 网上可搜N多,解决办法都差不多,其中一种: add_header Access-Control-Allow-Origin http://xxxx:port; add_header ...

  3. Codeforces 455B A Lot of Games

    http://codeforces.com/contest/455/problem/B 题目大意: 给出n个字符串,进行k次游戏,每次游戏输家下次作为先手,游戏规则为每次放一个字母,导致当前构造的字符 ...

  4. 从客户端(txtNewsContent="<hr />")中检测到有潜在危险的 Request.Form 值。怎么办呀?

    <system.web><httpRuntime requestValidationMode="2.0" executionTimeout="3600& ...

  5. MCS-51单片机实用子程序库

    目前已有若干版本的子程序库公开发表,它们各有特色.本程序库中的开平方算法为快速逼近算法,它能达到牛顿迭代法同样的精度,而速度加快二十倍左右,超过双字节定点除法的速度. 本子程序库对<单片机应用程 ...

  6. java比较相等符

    public class Test1 { /** * @param args */ public static void main(String[] args){ int a = 1000, b = ...

  7. Java并发编程:性能、扩展性和响应

    1.介绍 本文讨论的重点在于多线程应用程序的性能问题.我们会先给性能和扩展性下一个定义,然后再仔细学习一下Amdahl法则.下面的内容我们会考察一下如何用不同的技术方法来减少锁竞争,以及如何用代码来实 ...

  8. JAVA并发实现五(生产者和消费者模式wait和notify方式实现)

    package com.subject01; import java.util.PriorityQueue; /** * 通过wait和notify 实现 * 生产者-消费者模型:当队列满时,生产者需 ...

  9. for的用法

    第一次看到这么用,哈哈,就记下 for (var control = ["程", "陈", "是"]; control[0]; contro ...

  10. OpenMp 基本

      OpenMp是由OpenMP Architecture Review Board牵头提出的,并已被广泛接受的,用于共享内存并行系统的多线程程序设计的一套指导性的编译处理方案(Compiler Di ...