题意:计算给定矩形面积(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. CSS的定位属性实现text-shadow属性的文本下产生阴影效果

    只要先理解text-shadow的原理,就能用定位元素进行效果的模仿. text-shadow: h-shadiv v-shadov blur color h-shadv为文本水平移动的距离,正值相对 ...

  2. eclipse颜色配置

    Eclipse颜色主题插件:Eclipse Color Theme http://blog.sina.com.cn/s/blog_674212810101go8x.html 一个很赞的eclipse插 ...

  3. c++实现文本中英文单词和汉字字符的统计

    源代码下载:http://download.csdn.net/detail/nuptboyzhb/4987141 1.统计文本中汉字的频数,为后续的文本分类做基础.对于汉字的统计,需要判断读取的是否为 ...

  4. 使用rsyslog+loganalzey收集日志显示客户端ip

    http://www.ituring.com.cn/article/128536 rsyslog localhost 转发 http://bigsec.net/one/tool/rsyslog.htm ...

  5. 扩展DJANGO的LISTVIEW

    不用MODEL,不用QUERYSET,而用get_queryset方法来扩展LISTVIEW, 从而实现特定过滤或搜索功能. class DVListView(ListView): template_ ...

  6. hdu 4678 Mine 博弈论

    这是一题简单的博弈论!! 所有的空白+边界的数字(个数为n)为一堆,容易推出其SG函数值为n%2+1: 其他所有的数字(个数为m)的SG值为m%2. 再就是用dfs将空白部分搜一下即可!(注意细节) ...

  7. hdu 3864 D_num

    思路:给一个数n,是否只有4个约数(包括1),也就是找3个大于1的约数. 而任何一个数都可由质数表示,所以对于给定的数,只需要进行质因数分解.这里有 2种情况:如果有3个一样的质因数,则满足条件:否则 ...

  8. hbase总结:如何监控region的性能

    转载:http://ju.outofmemory.cn/entry/50064 随着大数据表格应用的驱动,我们的HBase集群越来越大,然而由于机器.网络以及HBase内部的一些不确定性的bug,使得 ...

  9. SaaS系列介绍之七: SaaS模式分析(下)

    1 SaaS模式下的质量管理 质量管理是从事SaaS事业的企业管理的重要课题,质量管理的职能是质量方针.质量目标和质量指标的制定和贯彻实施,中心目标是促进产品质量.提高客户满意度. 软件质量要素包含以 ...

  10. Qt的版本历史

    发展史 Qt的第一个商业版本于1995年推出,随后Qt的发展就很快了,下面是Qt发展史上的一 些里程碑,从之前的Qt1.x开始到现在的Qt5.x. Qt1-3 版本 发布日期 1.40 10 July ...