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 ...
随机推荐
- c++ 读写锁
#ifndef THREAD_UTIL_H #define THREAD_UTIL_H #include <pthread.h> namespace spider { class Auto ...
- 【leetcode】Word Break II (hard)★
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each ...
- mvc+entity framework database first,生成的model每次更新一个表会更新所有的model
在使用Entity Framework 的Database frist或model first时,直接加attribute到modle类上是太现实也不合理的,因为model类是自动生成的,重新生成后会 ...
- 并发下常见的加锁及锁的PHP具体实现
http://www.cnblogs.com/scotoma/archive/2010/09/26/1836312.html Apache + PHP 的并发访问 http://www.cnblogs ...
- Android 使用split函数进行多个空格分割
在项目中经常会遇到按字符分割字符串的情况,可以使用String对象的split函数进行分割. 先看实际情况: String str = "关键词1 关键词2 关键词3"; Stri ...
- C#解析.msg文件(outlook文件)
起因 有一批邮件(700+),全是 .msg 文件,是同群发邮件产生的退信,这些退信需要作分析,得出退信产生的原因. 解决方法 在网上搜了一下发现 .msg文件有其自己的格式,MS提供了格式说明,自己 ...
- puppet&mcollective客户端安装
一.环境: 1.客户端: fedora 19 2.DnsServer: 192.168.0.160 3.server1.xxx.com(10.8.1.201):运行以下服 ...
- RabbitMQ消息队列(一): Detailed Introduction 详细介绍(转)
1. 历史 RabbitMQ是一个由erlang开发的AMQP(Advanced Message Queue )的开源实现.AMQP 的出现其实也是应了广大人民群众的需求,虽然在同步消息通讯的世界里有 ...
- NPOI的源代码编译
打开版本库下的examples文件夹 然后打开对应的解决方案文件,尝试编译程序.发现提示缺少了dll 琢磨了半天,找到四个项目文件,打开之后进行编译.最后会生成dll到solution文件夹下的Lib ...
- .NET中各种不同的Timer之间区别
System.Timer.Timer 根据命名空间看这个类貌似才是标准的Timer,它提供Interval属性和Elapsed事件.可以每隔一个时间周期触发一次Elapsed事件.在ThreadPoo ...