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个盒子里的方案数. 这个问题可以用隔板法(插 ...
随机推荐
- cf B. Road Construction
http://codeforces.com/contest/330/problem/B这道题可以围着一个可以与任何一个城市建路的城市建设. #include <cstdio> #inclu ...
- CPU卡读写程序
CPU卡也称智能卡,卡内的集成电路中带有微处理器CPU.存储单元(包括随机存储器RAM.程序存储器ROM以及芯片操作系统COS.装有COS的CPU卡相当于一台微型计算机,不仅具有数据存储功能,同时具有 ...
- SQLServer 安装以前的某个程序安装已在安装计算机上创建挂起的文件操作 解决办法
http://wenku.baidu.com/view/6732fe09844769eae009ede2.html SQL Server 安装以前的某个程序安装已在安装计算机上创建挂起的文件操作 安装 ...
- VS项目如何添加到svn
SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.这里就讲一下VS2010如何将项目导入SVN版本控制. 工具 ...
- c#类和结构体的关系
原文地址:http://www.dnbcw.com/biancheng/c/fvhc81798.html 简介:这是c#类和结构体的关系的详细页面,介绍了和c/c++,有关的知识,谢谢大家的观看!要查 ...
- 自制USB wifi信号放大天线
这是我的usb wifi天线第一个版本,灵感来自: http://www.instructables.com/id/EQARE4I72GEPUCHTHU/ http://www.usbwifi.orc ...
- 传智播客 Html基础知识学习笔记2
一.<select>标签 用来创建类似于WinForm中的ComboBox(下拉列表)或者LisBox 如果size大于1就是LisBox,否则就是ComboBox; <select ...
- jQuery插件开发 格式与解析
jQuery插件的开发包括两种: 一种是类级别的插件开发,即给jQuery添加新的全局函数,相当于给jQuery类本身添加方法.jQuery的全局函数就是属于jQuery命名空间的函数,另一种是对象级 ...
- Android状态栏颜色修改
android状态栏颜色修改 状态栏颜色的修改在4.4和5.x环境下分别有不同的方式,低于4.4以下是不能修改的. 5.x环境下 方式一,状态栏将显示为纯净的颜色,没有渐变效果 /** * 状 ...
- FragmentPagerAdapter与FragmentStatePagerAdapter差异
平常使用的FragmentPagerAdapter和FragmentStatePagerAdapter来自android.support.v4.app包用来构建ViewPager. FragmentP ...