以前已经做过一次这样的题,第二次做还是没能一A 。。。。
一直卡在输入上,学长说把scanf() 换成 cin ,然后果断A掉了。
以此为戒吧,以后碰到类似的输入,记得用cin........Orz
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define EPS (1e-8)
#define Left true
#define Right false
using namespace std;
char sta[13][11];
bool mark[13][11];
struct N
{
int x,y;
};
void del()
{
int i,j,k;
for(i = 1;i <= 10; ++i)
{
for(j = 1;j <= 12; ++j)
{
if(mark[j][i] == true)
{
sta[j][i] = '1';
}
}
for(j = 1;j <= 12; ++j)
{
for(k = 1;k < 12; ++k)
{
if(sta[k][i] == '1')
{
sta[k][i] = sta[k+1][i];
sta[k+1][i] = '1';
}
}
}
}
for(k = 1;k <= 10; ++k)
{
for(i = 1;i <= 9; ++i)
{
for(j = 1;j <= 12 && sta[j][i] == '1'; ++j)
;
if(j == 13)
{
for(j = 1;j <= 12; ++j)
{
sta[j][i] = sta[j][i+1];
sta[j][i+1] = '1';
}
}
}
}
}
int jx[] = { 0,-1, 0, 1};
int jy[] = { 1, 0,-1, 0};
int bfs(int x,int y)
{
if(sta[x][y] == '1')
return 0;
int ans = 1;
queue<N> q;
N st,ft;
st.x = x,st.y = y;
q.push(st);
mark[st.x][st.y] = true;
while(q.empty() == false)
{
ft = q.front();
q.pop();
for(int i = 0;i < 4; ++i)
{
st = ft;
st.x += jx[i];
st.y += jy[i];
if(1 <= st.x && st.x <= 12 && 1 <= st.y && st.y <= 10 && sta[st.x][st.y] == sta[ft.x][ft.y] && mark[st.x][st.y] == false)
{
q.push(st);
mark[st.x][st.y] = true;
ans++;
}
}
}
if(ans <= 2)
{
memset(mark,false,sizeof(mark));
ans = 0;
}
return ans;
}
int main()
{
int n;
int x,y;
char c;
int i,j;
int sum;
while(scanf("%d%*c",&n) && n)
{
sum = 120;
for(i = 12;i >= 1; --i)
{
for(j = 1;j <= 10; ++j)
{
cin>>sta[i][j];
}
}
while(n--)
{
cin>>c>>x;
y = c-'a'+1;
memset(mark,false,sizeof(mark));
sum -= bfs(x,y);
del();
}
cout<<sum<<endl;
}
return 0;
}