rt 在本帖回答
#include<bits/stdc++.h>
using namespace std;
int n;
int m;
int cnt;
int x;
int a[15];
string s;
bool check1()
{
int s=a[1];
for(int i=2;i<=9;i++)
{
if(s==a[i] || a[i]==-1)
{
return 0;
}
}
a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=-1;
m+=8;
return 1;
}
bool check2()
{
bool f;
for(int i=1;i<=9;i++)
{
for(int j=1;j<=9;j++)
{
if(a[i]==a[j] && i!=j && a[i]!=-1 && a[j]!=-1)
{
a[i]=a[j]=-1;
m++;
return 1;
}
}
}
return 0;
}
bool check3(int i,int j,int k)
{
if(a[i]==a[j] && a[j]==a[k] && a[i]!=-1)
{
a[i]=a[j]=a[k]=-1;
m+=2;
return 1;
}
return 0;
}
bool chack4()
{
return check3(1, 2, 3) || check3(4, 5, 6) || check3(7, 8, 9) ||
check3(1, 4, 7) || check3(2, 5, 8) || check3(3, 6, 9) ||
check3(1, 5, 9) || check3(3, 5, 7);
}
int main()
{
freopen("turtle.in","r",stdin);
freopen("turtle.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>x;
cin>>s;
a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=-1;
while(cnt<m)
{
for(int i=1;i<=9;i++)
{
if(a[i]==-1 && cnt<m)
{
a[i]=s[cnt]-'0';
if(a[i]==x)
{
m++;
}
cnt++;
}
}
bool f=1;
while(f)
{
f=0;
if(check1())
{
f=1;
}
if(chack4())
{
f=1;
}
if(check2())
{
f=1;
}
}
}
cout<<cnt;
return 0;
}