链接P1101 单词方阵
感想
感觉这做一题需要的时间也太长了一点,一个半小时??不过断点调试这个功能真的不是一般的好用,当然还是写代码的时候脑子清楚一点更好,这个难度起不到练习的作用…但是只有做完了才知道…唉,这个难度的控制也是个问题…
code
#include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;
char words[] = "yizhong";
const int maxn = 1005;
int n;
char m[100+5][100+5];
int show[100+5][100+5]={0};
int leftt[] = {1, 1, 1, -1, -1, -1, 0, 0, 0};
int upp[] = {1, -1, 0, 1, -1, 0, 1, -1, 0};
bool dfs_1(int i, int j,int kk, int k)
{
int dis_x = i + leftt[kk];
int dis_y = j + upp[kk];
if (dis_x>=0&&dis_x<n&&dis_y>=0&&dis_y<n)
{
if(m[dis_x][dis_y] == words[k] && k!=6)
{
if(dfs_1(dis_x, dis_y, kk, k+1) == true)
{
show[i][j] = 1;
return true;
}
else
{
return false;
}
}
else if(m[dis_x][dis_y] == words[k] && k == 6)
{
show[dis_x][dis_y] = 1;
show[i][j] = 1;
return true;
}
else
{
return false;
}
}
else
{
return false;
}
return false;
}
void dfs(int i, int j, int k)
{
for(int kk=0;kk<9;kk++)
{
int dis_x = i + leftt[kk];
int dis_y = j + upp[kk];
if (dis_x>=0&&dis_x<n&&dis_y>=0&&dis_y<n)
{
if(m[dis_x][dis_y] == words[k+1])
{
if(dfs_1(i, j, kk, k+1))
{
show[i][j] = 1;
}
}
}
else
{
continue;
}
}
}
int main()
{
#ifdef LOCAL
freopen("C:\\Users\\hsxny\\Desktop\\in.txt", "r", stdin);
#endif
cin>>n;
for(int i=0;i<n;i++)
{
scanf("%s", m[i]);
}
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(m[i][j] == 'y')
{
dfs(i, j, 0);
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(show[i][j])
{
cout<<m[i][j];
}
else
{
cout<<"*";
}
}
cout<<endl;
}
return 0;
}