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的面向对象的程序设计之理解继承
来自<javascript高级程序设计 第三版:作者Nicholas C. Zakas>的学习笔记(六) 先来解析下标题——对象和继承~ 一.对象篇 ECMA-262把对象的定义为:&qu ...
- [转载]async & await 的前世今生
async 和 await 出现在C# 5.0之后,给并行编程带来了不少的方便,特别是当在MVC中的Action也变成async之后,有点开始什么都是async的味道了.但是这也给我们编程埋下了一些隐 ...
- c++中的隐藏、重载、覆盖(重写)
转自c++中的隐藏.重载.覆盖(重写) 1 重载与覆盖 成员函数被重载的特征: (1)相同的范围(在同一个类中): (2)函数名字相同: (3)参数不同: (4)virtual关键字可有可无. 覆盖是 ...
- nginx上用fastcgi配置python环境
费了2天的功夫,翻阅了无数的中文.英文资料,终于搞定.写下此文留待以后翻阅用 本文环境,centOS 5.4 ,Nignx-0.8.49, Python 2.6.5 ========== ...
- POJ 1797 Heavy Transportation(Dijkstra)
http://poj.org/problem?id=1797 题意 :给出N个城市M条边,每条边都有容量值,求一条运输路线使城市1到N的运输量最大. 思路 :用dijkstra对松弛条件进行变形.解释 ...
- UrlRewriteFilter 美化器的使用方法 伪静态化的解决方案(转)
一,URL美化器简介 UrlRewriteFilter是一个用于改写URL的Web过滤器,类似于Apache的mod_rewrite.适用于任何Web应用服务器(如Resin,Orion,Tomcat ...
- JVM并发机制的探讨——内存模型、内存可见性和指令重排序
并发本来就是个有意思的问题,尤其是现在又流行这么一句话:“高帅富加机器,穷矮搓搞优化”. 从这句话可以看到,无论是高帅富还是穷矮搓都需要深入理解并发编程,高帅富加多了机器,需要协调多台机器或者多个CP ...
- SQL四种语言:DDL,DML,DCL,TCL
1.DDL(Data Definition Language)数据库定义语言statements are used to define the database structure or schema ...
- 102. Binary Tree Level Order Traversal
题目: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to ri ...
- php修改排序,上移下移
php修改排序,上移下移 /** $UpDown //移动方向,up或down $table //表名 $id //当前移动的ID $id_col //ID字段的名称 $ ...