题意:计算给定矩形面积(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的更多相关文章

  1. Good Bye 2015 C. New Year and Domino 二维前缀

    C. New Year and Domino   They say "years are like dominoes, tumbling one after the other". ...

  2. 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 ...

  3. TTTTTTTTTTTTT CF Good Bye 2015 C- New Year and Domino(CF611C) 二维前缀

    题目 题意:给你一个n*m由.和#组成的矩阵,.代表可以放,#代表不可以,问在左上角(px,py)到(右下角qx,qy)这样的一个矩阵中,放下一个长度为2宽度为1的牌有多少种放法: #include ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Good Bye 2015 C

    C. New Year and Domino time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. Extjs4 treePanel异步加载菜单(后台从数据库读取)

    运行环境:springMVC+mybatis 一.建表 说明:0表示此节点为非叶子节点,即此节点还包括了子节点:1表示此节点为叶子节点,即此节点没有子节点.:关于图标iconCls是从Extjs的文件 ...

  2. hibernate简介(Session,几种状态,方法······等)

    1.Hibernate是什么?          Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数 ...

  3. uva 558 Bellman_Ford

    Bellman_Ford算法   求图中是否存在负权值的回路   若图中不存在   则最短路最多经过n-1个结点   若经过超过n-1个节点 则存在负权值的回路  此图永远无法找到最短路  每条边最多 ...

  4. c/c++ define用法

    define,无参宏定义的一般形式为:#define 标识符 字符串 外文名 define 词条范围 计算机专业用语 无参一般形式 #define 标识符 字符串 带参一般形式 #define 宏名( ...

  5. 用MT.exe将exe中的manifest文件提取出来和将manifest文件放入exe中

     前一种方法是将manifest文件放入exe中,但是要记得需要在工程中设置 这样的话exe中就不存在manifest了,在debug目录下就会看到相应的manifest文件.后者是将exe中的man ...

  6. <context:component-scan>配置解析(转)

    在xml配置了这个标签后,spring可以自动去扫描base-pack下和其子包下面的java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类注 ...

  7. 图形学:图像围绕着某个点P(a,b)旋转------白话版

    前提:在研究图形时候,我们并没有规定图形的大小,所以任意图形多是支持的,这也另外说明了一点,图形转换和图形的大小没有关系. 如果图像围绕着某个点P(a,b)旋转,则先要将坐标系平移到该点,再进行旋转, ...

  8. SaaS系列介绍之九: SaaS营销模式分析

    1 配置模式 中国企业很多是人治,管理弹性非常大,公司的政策经常变化,管理流程.业务变化也非常大,发展也非常快;一个公司今年是10个人,明年是100个人,后年可能是1000人.管理机制.方法处于经常变 ...

  9. 92. Reverse Linked List II

    题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1- ...

  10. Kali2.0 Sqlmap清除历史扫描日志

    使用Sqlmap扫描SQL注入漏洞时,首次扫描会在SQL的/root/.sqlmap/output/目录下留下 以IP地址为名称的文件夹,如下所示: 而如果该安全漏洞经过修复后,再次使用SQLMAP扫 ...