分析
竟然一遍 A 了,写篇题解纪念一下。
如果一个灯管一直都是 X
或者一直都是 .
,那它就有可能恒亮或恒灭。
枚举起始时间,那么如果一个不可能恒亮或恒灭的灯管没有正常发光,那么这个起始时间就不合法。
如果对于某个起始时间,某个灯管都正常发光,那它就有可能是正常工作的。
如果一个灯管的可能性超过 $2$ 种,那么就输出 ?
,否则输出对应的东西即可。
难点主要在于码,但是想清楚了也不是很难写。
代码
打表代码警告
// ====================================
// author: M_sea
// website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
int read() {
int X=0,w=1; char c=getchar();
while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
return X*w;
}
const int N=100+10;
const int R[8][22]={
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,1,1,0},
{0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1},
{0,1,0,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,0,1},
{0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,1,1,0},
{0,1,0,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,0,1},
{0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1},
{0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,1,1,0},
};
const int G[10][7][4]={{
{0,1,1,0},
{1,0,0,1},
{1,0,0,1},
{0,0,0,0},
{1,0,0,1},
{1,0,0,1},
{0,1,1,0}
},{
{0,0,0,0},
{0,0,0,1},
{0,0,0,1},
{0,0,0,0},
{0,0,0,1},
{0,0,0,1},
{0,0,0,0}
},{
{0,1,1,0},
{0,0,0,1},
{0,0,0,1},
{0,1,1,0},
{1,0,0,0},
{1,0,0,0},
{0,1,1,0}
},{
{0,1,1,0},
{0,0,0,1},
{0,0,0,1},
{0,1,1,0},
{0,0,0,1},
{0,0,0,1},
{0,1,1,0}
},{
{0,0,0,0},
{1,0,0,1},
{1,0,0,1},
{0,1,1,0},
{0,0,0,1},
{0,0,0,1},
{0,0,0,0}
},{
{0,1,1,0},
{1,0,0,0},
{1,0,0,0},
{0,1,1,0},
{0,0,0,1},
{0,0,0,1},
{0,1,1,0}
},{
{0,1,1,0},
{1,0,0,0},
{1,0,0,0},
{0,1,1,0},
{1,0,0,1},
{1,0,0,1},
{0,1,1,0}
},{
{0,1,1,0},
{0,0,0,1},
{0,0,0,1},
{0,0,0,0},
{0,0,0,1},
{0,0,0,1},
{0,0,0,0}
},{
{0,1,1,0},
{1,0,0,1},
{1,0,0,1},
{0,1,1,0},
{1,0,0,1},
{1,0,0,1},
{0,1,1,0}
},{
{0,1,1,0},
{1,0,0,1},
{1,0,0,1},
{0,1,1,0},
{0,0,0,1},
{0,0,0,1},
{0,1,1,0}
}
};
int n;
char s[N][8][25],a[8][25];
bool same[8][25],is1[8][25],is0[8][25],ok[8][25];
void paint(int x,int y,int c) {
for (int i=0;i<7;++i)
for (int j=0;j<4;++j)
a[x+i][y+j]=G[c][i][j]?'X':'.';
}
bool check(int h,int m) {
for (int i=1;i<=7;++i)
for (int j=1;j<=21;++j) same[i][j]=1;
for (int t=1;t<=n;++t) {
for (int i=1;i<=7;++i)
for (int j=1;j<=21;++j) a[i][j]='.';
if (h>=10) paint(1,1,h/10);
paint(1,6,h%10);
paint(1,13,m/10);
paint(1,18,m%10);
a[3][11]=a[5][11]='X';
for (int i=1;i<=7;++i)
for (int j=1;j<=21;++j)
same[i][j]&=(s[t][i][j]==a[i][j]);
++m;
if (m==60) ++h,m=0;
if (h==24) h=0;
}
for (int i=1;i<=7;++i)
for (int j=1;j<=21;++j)
if (!same[i][j]&&!is1[i][j]&&!is0[i][j]) return 0;
for (int i=1;i<=7;++i)
for (int j=1;j<=21;++j)
if (same[i][j]) ok[i][j]=1;
return 1;
}
int main() {
n=read();
for (int i=1;i<=n;++i) {
for (int j=1;j<=7;++j) fgets(s[i][j]+1,24,stdin);
if (i!=n) fgets(s[0][0],24,stdin);
}
for (int i=1;i<=7;++i)
for (int j=1;j<=21;++j) is1[i][j]=is0[i][j]=1;
for (int i=1;i<=7;++i)
for (int j=1;j<=21;++j) {
if (!R[i][j]) continue;
is1[i][j]=is0[i][j]=1;
for (int k=1;k<=n;++k) {
if (s[k][i][j]=='.') is1[i][j]=0;
if (s[k][i][j]=='X') is0[i][j]=0;
}
}
int flag=0;
for (int h=0;h<24;++h)
for (int m=0;m<60;++m)
if (check(h,m)) flag=1;
if (!flag) { puts("impossible"); return 0; }
for (int i=1;i<=7;++i) {
for (int j=1;j<=21;++j) {
if (!R[i][j]) putchar('.');
else {
int s=is1[i][j]+is0[i][j]+ok[i][j];
if (s>=2) putchar('?');
else {
if (is1[i][j]) putchar('1');
if (is0[i][j]) putchar('0');
if (ok[i][j]) putchar('W');
}
}
}
puts("");
}
return 0;
}
2 条评论
一遍 A 了!!1
Orz M_sea!