codeforces 611C
来源:互联网 发布:win10软件很模糊 编辑:程序博客网 时间:2024/06/05 10:39
题意:
给你一个矩阵,矩阵里有” . “和” # “,” . “表示空的,” # “表示禁止的。
多米诺骨牌将占据正好有两个相邻的单元格,或者位于一排或一列。两个相邻的单元格必须是空的,并且必须是一个网格内。对于每个询问,求给定矩形里面能组成不同多米诺骨牌的方式。
思路:
对于一段连续空的,我们能算出来,他的方法是n-1个。
=>求给定矩阵在行和列上的连续空的有多长。
一个挺好的方案:开两个数组直接记录,然后对于给定矩形,枚举每行每列,直接减一下,全部加起来就是answer。
感觉有点小神奇的方法。。。
#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef unsigned long long ULL;const double eps=1e-6;const double pi=acos(-1.0);const int mod=998244353;const int INF=0x3f3f3f3f;const int N=1e2+10;char ma[N*5][N*5];int n[N*5][N*5];int m[N*5][N*5];int main(){ int i,j,h,w; scanf("%d%d",&h,&w); for(i=0;i<h;i++) scanf("%s",ma[i]); memset(n,0,sizeof(n)); memset(m,0,sizeof(m)); for(i=0;i<h;i++) { for(j=0;j<w;j++){ if(j>0&&ma[i][j]=='.'&&ma[i][j]==ma[i][j-1]) n[i][j]=n[i][j-1]+1; else n[i][j]=n[i][j-1]; if(i>0&&ma[i][j]=='.'&&ma[i-1][j]==ma[i][j]) m[i][j]=m[i-1][j]+1; else m[i][j]=m[i-1][j]; } } LL ans; int q; int x1,x2,y1,y2; scanf("%d",&q); while(q--){ ans=0; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); x1--; y1--; x2--; y2--; for(i=x1;i<=x2;i++) ans+=n[i][y2]-n[i][y1]; for(j=y1;j<=y2;j++) ans+=m[x2][j]-m[x1][j]; printf("%I64d\n",ans); } return 0;}
0 0
- Codeforces 611C
- codeforces 611C
- codeforces-611C-New Year and Domino
- CodeForces 611C New Year and Domino
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- codeforces 148 div2 C
- codeforces 242C
- Codeforces-234C Weather
- codeforces 106C Buns
- codeforces 158C
- J2EE进阶(十)SSH框架整合常见问题汇总(一)
- OpenGL模拟太阳系运行
- 树莓派 RECALBOX 复合电视信号输出配置
- python的内建函数
- 常用算法思想:穷举算法思想
- codeforces 611C
- CSS content、padding、border、margin属性
- 细谈0、false、null
- Android UI学习篇:ListView
- w3c js笔记
- HDU 2563 统计问题
- Codeforces 469A I Wanna Be the Guy
- hdoj 1052 Tian Ji -- The Horse Racing
- Learning Deep Features for Discriminative Localization论文笔记以及Caffe实现