Good Bye 2015 C - New Year and Domino
题意:计算给定矩形面积(r1,c1),(r2,c2)内长度为2的有多少个?向右或向下计算。
思路:预处理字符。分别向右和向下处理。注意边界情况,可能算多了。用容斥原理计算长度为二的单位。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define clc(a,b) memset(a,b,sizeof(a))
const int maxn=; char str[][];
int persum[][];
int rightt[][];
int down[][];
int n,m,r1,r2,c1,c2; void init()
{
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
if(str[i][j]=='.'&&str[i][j+]=='.')
{
rightt[i][j]=;
persum[i][j]++;
}
if(str[i][j]=='.'&&str[i+][j]=='.')
{
down[i][j]=;
persum[i][j]++;
}
persum[i][j]+=persum[i-][j]+persum[i][j-]-persum[i-][j-];
}
}
} int main()
{
// freopen("in.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
int q;
clc(persum,);
clc(rightt,);
clc(down,);
for(int i=; i<=n; i++)
scanf("%s",str[i]+);
init();
cin>>q;
while(q--)
{
cin>>r1>>c1>>r2>>c2;
int cnt=;
cnt=persum[r2][c2]-persum[r2][c1-]-persum[r1-][c2]+persum[r1-][c1-];
for(int i=r1; i<=r2; i++)
if(rightt[i][c2]) cnt--;
for(int j=c1; j<=c2; j++)
if(down[r2][j])cnt--;
cout<<cnt<<endl;
}
}
return ;
}
Good Bye 2015 C - New Year and Domino的更多相关文章
- Good Bye 2015 C. New Year and Domino 二维前缀
C. New Year and Domino They say "years are like dominoes, tumbling one after the other". ...
- Codeforces Good Bye 2015 C. New Year and Domino 前缀和
C. New Year and Domino 题目连接: http://www.codeforces.com/contest/611/problem/C Description They say &q ...
- TTTTTTTTTTTTT CF Good Bye 2015 C- New Year and Domino(CF611C) 二维前缀
题目 题意:给你一个n*m由.和#组成的矩阵,.代表可以放,#代表不可以,问在左上角(px,py)到(右下角qx,qy)这样的一个矩阵中,放下一个长度为2宽度为1的牌有多少种放法: #include ...
- Good Bye 2015 D. New Year and Ancient Prophecy
D. New Year and Ancient Prophecy time limit per test 2.5 seconds memory limit per test 512 megabytes ...
- Good Bye 2015 B. New Year and Old Property 计数问题
B. New Year and Old Property The year 2015 is almost over. Limak is a little polar bear. He has re ...
- Good Bye 2015 A. New Year and Days 签到
A. New Year and Days Today is Wednesday, the third day of the week. What's more interesting is tha ...
- Codeforces Good bye 2015 B. New Year and Old Property dfs 数位DP
B. New Year and Old Property 题目连接: http://www.codeforces.com/contest/611/problem/B Description The y ...
- Codeforces Good Bye 2015 A. New Year and Days 水题
A. New Year and Days 题目连接: http://www.codeforces.com/contest/611/problem/A Description Today is Wedn ...
- Good Bye 2015 C
C. New Year and Domino time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- js 判断文件是否存在(转载)
js 判断文件是否存在(转载) var fso,s=filespec; // filespec="C:/path/myfile.txt"fso=new ActiveXObject ...
- 线程以及数据对象的wait()和notifyAll()方法
正在运行的程序称作一个进程,一个进程可以包含多个线程,这些线程可以共享进程的资源,它们共用一块存储空间.那么,各个线程在访问同一个数据对象的同时,可能引起冲突,以生产者.消费者为例,就会出现队列中没有 ...
- scikit-learn安装
1.依赖包: Cython.rose.numpy.scipy.lapack.atlas http://blog.chinaunix.net/uid-22488454-id-3978860.html
- 1988-B. 有序集合
描述 在C++里,有一个神奇的东西,叫做STL,这里提供了很多简单好用的容器,用来实现常用又很难书写的数据结构,如栈(stack)等.其中,有一个容器叫set,译作“有序集合”.首先,这是一个集合,所 ...
- 命令格式 kill -3 pid
命令格式 kill -3 pid 作用 打印进程号为pid的进程中,每个线程的执行日志 到 nohup文件 中,如果nohup的输出做了重定向,那么输出到重定向以后的文件中. 命令格式 top -Hp ...
- 二维图形的矩阵变换(三)——在WPF中的应用矩阵变换
原文:二维图形的矩阵变换(三)--在WPF中的应用矩阵变换 UIElement和RenderTransform 首先,我们来看看什么样的对象可以进行变换.在WPF中,用于呈现给用户的对象的基类为Vis ...
- WPF中动态添加xaml资源文件
一.新建一个资源文件,然后设置其Build Actoin(生成操作)为Resource(资源): 二.在App.xaml.cs的StartUp事件或者是你需要的时机代码段写上如下代码: Resourc ...
- profile工具
gprof callgrind vtune(待使用) ----time命令(待学习) ps -u <username> -H -opid,cmd strace
- 【HDOJ】4333 Revolving Digits
扩展KMP基础题目. /* 4333 */ #include <iostream> #include <sstream> #include <string> #in ...
- Android开发之读写联系人
读写联系人需要用到android的ContentProvider 同时需要读和写联系人的权限 需要使用到联系人数据库中的 * raw_contacts表: * contact_id:联系人id * d ...