TTTTTTTTTTTTT CF Good Bye 2015 C- New Year and Domino(CF611C) 二维前缀
题意:给你一个n*m由.和#组成的矩阵,.代表可以放,#代表不可以,问在左上角(px,py)到(右下角qx,qy)这样的一个矩阵中,放下一个长度为2宽度为1的牌有多少种放法;
#include <iostream>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
const int mod=100000000;
ll max(ll a,ll b)
{return a>b?a:b;};
int min(int a,int b)
{return a<b?a:b;}; const int max_=500;
int r[max_+5][max_+5],l[max_+5][max_+5],ans[100000+5];
char f[505][505];
int q,px,py,qx,qy,n,m; void init()
{
MM(r,0);MM(l,0);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(f[i][j]=='.'&&f[i-1][j]=='.') l[i][j]++;
if(f[i][j]=='.'&&f[i][j-1]=='.') r[i][j]++;
r[i][j]+=r[i-1][j]+r[i][j-1]-r[i-1][j-1];
l[i][j]+=l[i-1][j]+l[i][j-1]-l[i-1][j-1];
}
} int main()
{
while(~scanf("%d %d",&n,&m))
{
for(int i=1;i<=n;i++)
{
scanf("%s",f[i]);
for(int j=m-1;j>=0;j--)
f[i][j+1]=f[i][j];
f[i][0]='#';
}
init();
scanf("%d",&q);
for(int i=1;i<=q;i++)
{
scanf("%d %d %d %d",&px,&py,&qx,&qy);
ans[i]=r[qx][qy]-r[qx][py]-r[px-1][qy]+r[px-1][py];
ans[i]+=l[qx][qy]-l[qx][py-1]-l[px][qy]+l[px][py-1];
//这个地方需要细心一点,不是单纯的和计算面积一样,需要考虑牌的放法
}
for(int i=1;i<=q;i++)
printf("%d\n",ans[i]);
}
return 0;
}
分析:本来还以为位是迷宫问题,后来看了题解后才发现只要处理下二维前缀就好,l,r数组分别代表
从左上角到(i,j)这个点分别按能行吗,列所能放置的种数
TTTTTTTTTTTTT CF Good Bye 2015 C- New Year and Domino(CF611C) 二维前缀的更多相关文章
- 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 ...
- Good Bye 2015 C - New Year and Domino
题意:计算给定矩形面积(r1,c1),(r2,c2)内长度为2的有多少个?向右或向下计算. 思路:预处理字符.分别向右和向下处理.注意边界情况,可能算多了.用容斥原理计算长度为二的单位. #inclu ...
- CF Gym 100463D Evil (二维前缀和+离散)
题意:给一些带颜色的点,求一个最小的矩形,恰好包括一半的红色点,且不包括蓝色点. 题解:暴力,求个二维前缀和,用容斥原理更新一下.N很小所以我采用了离散优化,跑了个0ms. 之前没写过二维前缀和,加上 ...
- CODESOFT 2015中的二维码该怎样生成
由于二维条码具有储存量大.保密性高.追踪性高.抗损性强.备援性大.成本便宜等特性,其应用 渐趋广泛,因此二维码的制作对于CODESOFT条码设计软件的用户来讲可谓司空见惯.我们最常见的二维码要数QR码 ...
- 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 ...
随机推荐
- Spring(十三)-- Spring 事务
Spring 事务 1. 回忆之前事务知识点 一:事务的概念 将一系列的数据操作捆绑在一起,成为一个整体进行统一管理! 一条或者多条sql语句的集合! 二:事务的ACID特性 原子性(Atomic ...
- oracle 插入数据之坑--------oracle字符类型varchar2一个中文占多少字节
如果你误认为是两个字节,那就大错特错了 Oracle 一个中文汉字 占用几个字节,要根据Oracle中字符集编码决定 查看oracle server端字符集 select userenv('langu ...
- # [爬虫Demo] pyquery+csv爬取猫眼电影top100
目录 [爬虫Demo] pyquery+csv爬取猫眼电影top100 站点分析 代码君 [爬虫Demo] pyquery+csv爬取猫眼电影top100 站点分析 https://maoyan.co ...
- CentOS7 安装ffmpeg
安装EPEL Release,因为安装需要使用其他的repo源,所以需要EPEL支持:yum install -y epel-release#如果出现缺少Code提示,可以: sudo rpm --i ...
- cut--修剪小能手
cut命令 cut原理:以每一行位一个处理对象. 参数选项 解释说明 -b 以字节为单位进行分割 -c 以字符为单位进行分割(对切割中文有奇效) -d 自定义分隔符号,默认以tab为分隔符 1:-b ...
- vue路由守卫触发顺序
不同组件之间的路由跳转流程图 导航被触发(A–>B) 调用A组件内路由守卫beforeRouteLeave(to,from,next) 调用全局路由前置守卫router.beforeEach(t ...
- Swift(三)基本运算符
Swift支持大部分标准C语言的运算符,并且对许多特性进行改进来减少常规编码的错误.除了支持基本运算符外,Swift还提供了2个特殊的运算符,分别是:溢出运算符和区间运算符 首先看下基本运算符 imp ...
- 51. N-Queens (JAVA)
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...
- 查看jar包依赖树
在eclipse执行如下命令: 可以在控制台上查看层级依赖关系
- 08 自学Aruba之限制应用流量
点击返回:自学Aruba之路点击返回:自学Aruba集锦 08 自学Aruba之限制应用流量 限制带宽请查阅:点击 下文描述的步骤,主要是针对某一个SSID所用用户在使用某一个应用的时候设置共享带宽. ...