本人在今天下午的csp-s t1中使用了 lock 作为存储输入的变量名,luogu 自测显示ce,求存活概率(
代码如下
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
bool in_place[6];
int a[6][maxn];
int lock[6][10];
int tmp[6];
int cnt,n;
int pl[3];
void dfs(int step)
{
if(step==6) {cnt++;for(int i=1;i<=5;i++) a[i][cnt]=tmp[i];return;}
for(int i=0;i<=9;i++) {tmp[step]=i;dfs(step+1);}
}
bool judge2(int x,int y,int p,int q)
{
if(x-y==p-q) return true;
if(x-y+10==p-q) return true;
if(x-y==p-q+10) return true;
return false;
}
bool judge(int id)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=5;j++)
{
in_place[j]=0;
if(a[j][id]==lock[j][i]) in_place[j]=1;
}
int tot=0;
for(int j=1;j<=5;j++) {if(!in_place[j]) {if(tot==2) return false;pl[++tot]=j;}}
if(!tot) return false;
if(tot==2)
{
if(abs(pl[1]-pl[2])!=1) return false;
if(!judge2(a[pl[1]][id],lock[pl[1]][i],a[pl[2]][id],lock[pl[2]][i])) return false;
}
}
return true;
}
int main()
{
freopen("lock.in","r",stdin);
freopen("lock.out","w",stdout);
dfs(1);
/*for(int i=1;i<=cnt;i++)
{
for(int j=1;j<=5;j++)
cout<<a[j][i]<<' ';
cout<<endl;
}*/
cin>>n;
for(int i=1;i<=n;i++) for(int j=1;j<=5;j++) cin>>lock[j][i];
int ans=0;
for(int i=1;i<=cnt;i++) if(judge(i)) ans++;
cout<<ans<<endl;
return 0;
}
/*
2
2 8 3 5 5
2 8 3 5 1
*/