Codeforces 372B Counting Rectangles is Fun
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的更多相关文章
- Codeforces 372B Counting Rectangles is Fun:dp套dp
题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...
- 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 ...
- Codeforces 372 B. Counting Rectangles is Fun
$ >Codeforces \space 372 B. Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...
- 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 ...
- Counting Rectangles
Counting Rectangles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1043 Accepted: 546 De ...
- Project Euler 85 :Counting rectangles 数长方形
Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...
- UVA - 10574 Counting Rectangles
Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3 ...
- UVA 10574 - Counting Rectangles(枚举+计数)
10574 - Counting Rectangles 题目链接 题意:给定一些点,求可以成几个边平行于坐标轴的矩形 思路:先把点按x排序,再按y排序.然后用O(n^2)的方法找出每条垂直x轴的边,保 ...
- Codeforces 893E - Counting Arrays
893E - Counting Arrays 思路:质因子分解. 对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数. 相当于把k个小球分配到y个盒子里的方案数. 这个问题可以用隔板法(插 ...
随机推荐
- ASP.NET WEB API回发到客户端消息体的格式化
首先基于SOA的消息通信基本都是按照一个统一的协议规范进行交互,那么必须定义消息体.不同的交互结构设计了不同的消息体. 业界统一使用的SOAP是一种规范的XML消息内容.例如在WCF中返回的结果. 随 ...
- vs2010 suite integration toolkit execution
原因是UltraDeamen的问题,重新换个WinMount来解压ISO文件.完美安装运行
- poj3667---Hotel 线段树区间合并,区间更新
题意:有N个房间,M次操作.有两种操作(1)"1 a",表示找到连续的长度为a的空房间,如果有多解,优先左边的,即表示入住.(2)"2 b len",把起点为b ...
- Java并发实现一(并发的实现之Thread和Runnable的区别)
package com.subject01; public class ThreadOrRunnable { public static void main(String[] args) { Syst ...
- (转)iOS Wow体验 - 第六章 - 交互模型与创新的产品概念(2)
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第六章译文精选的第二部分,其余章节将陆续放出.上一 ...
- Git冲突解决方案
Git冲突解决方案 1. 在代码提交时,先更新,若有冲突.先解决冲突.若提交之后在review时才发现无法合并代码时有冲突,需要abandon此次提交的代码. 2. 解决冲突的基本做法,保存本地代 ...
- CoreText中坐标转换的一些理解
引言 学习CoreText,最初的想法是写一个杂志类的应用,因为对网易和zarca应用一些技术的疑问,所以,自己有了很强的兴趣欲和钻研欲,开始这段有点不顺的学习过程. 难题 1.对CGContextR ...
- this函数的理解
Javascript的this用法 this是Javascript语言的一个关键字. 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用.比如, function test(){ this. ...
- hive函数总结-字符串函数
hive 查看函数: show functions; parse_url: parse_url(url, partToExtract[, key]) - extracts a part from a ...
- 【Solr初探】Solr安装,启动,查询,索引
1. 安装&启动 官网:http://lucene.apache.org/solr/ 下载源代码,解压,进入根目录(我把solr放在/usr/local/solr下) 在/usr/local/ ...