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 ...
随机推荐
- 友善的树形DP
一棵树,如果有序点对(x,y)之间路径的长度取模于3==0,那么ans0便加上这个长度: 如果取模于3==1,那么ans1便加上这个长度: 如果取模于3==2,那么ans2便加上这个长度: 让你求an ...
- vscode中eslint插件的配置-prettier
用vue-cli构建vue项目,会有个eslint代码检测的安装 可vscode自带代码格式化是prettier格式(右键有格式化文件或alt+shift+f) 这时候要在vscode上装一个esli ...
- c# 不让窗体显示在alt tab中
protected override CreateParams CreateParams { get { const int WS_EX_APPWINDOW = 0x40000; const int ...
- js中自然日的计算
需求:前端取后端返回的时间与当前时间进行比较展示,展示规则: 1.返回的时间跟当前时间同年同月同日 显示 今天 2.返回的时间与当前时间相差在7天以内 显示 某天前 3.返回的时间与当前时间相差大于7 ...
- linux CUDA安装
首先是安装依赖库 sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-m ...
- 运行期优化 Java内存模型与线程 线程安全与优化
- RouterOS Firewall v6 流程图
1. Firewall v5和Firewall v6对比图 2.Firewall v6的流程图
- 批处理 使用默认浏览器 打开html文件
@echo offfor /f "tokens=3,4" %%a in ('"reg query HKEY_CLASSES_ROOT\http\shell\open\co ...
- kubeadm安装k8s1.13
1.环境介绍: centos 7.4.1708 关闭selinux和iptable,环境很重要! 主机 ip地址 cpu核数 内存 swap host解析 k8s-master 10.0.0.11 2 ...
- SpringBoot布道系列 | 目录汇总 | 2019持续更新ing
SpringBoot 基础教程 | 三大推荐理由 1.文章内容均为原创,结合官方文档和实战经验编写. 2.文章结构经过细致整理,对新人学习更加友好. 3.精选常用技术,不求全面,但求精华!! Spri ...