0%

poj 3690 Constellations

最近在翻 ICPC online 的题。。。
终于找到一个能做的水题结果WA了七八次。。。
可能我果然还是不会C/C++语言吧 OTZ

行状压和列状压都行吧。。。
然后我就暴力枚举右下角
感觉写的比能查到的题解好看一点。。。
【差点就全服最短了2333333

goto 什么的要谨慎。。。不行就写成函数嘛

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <cstdio>
typedef long long ll;
int n,m,t,p,q;
char map[1010][1010],pat[60][60];
ll ro[1010][1010],mat[60];
int main()
{
int cas=0;
while (scanf("%d%d%d%d%d",&n,&m,&t,&p,&q),n) {
for (int i=0;i<n;i++)
scanf("%s",map[i]);
ll mask=(1LL<<q)-1;//就因为只写了1没写LL结果WA了两小时。。。
for (int i=0;i<n;i++) {
ll tmp=0;
for (int j=0;j<m;j++)
ro[i][j]=tmp=((tmp<<1)|(map[i][j]=='*'))&mask;
}
int ans=0;
WCON:
while (t--) {
for (int i=0;i<p;i++)
scanf("%s",pat[i]);
for (int i=0;i<p;i++) {
ll tmp=0;
for (int j=0;j<q;j++)
tmp=(tmp<<1)|(pat[i][j]=='*');
mat[i]=tmp;
}
for (int i=p-1;i<n;i++) {
for (int j=q-1;j<m;j++)
if (ro[i][j]==mat[p-1]) {
int k=0;
while (k<p&&ro[i-k][j]==mat[p-1-k]) k++;
if (k==p) {
ans++;
goto WCON;
}
}
}
}
printf("Case %d: %d\n",++cas,ans);
}
return 0;
}
咖啡,亦我所需也