单词方阵

https://www.luogu.org/problemnew/show/P1101

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
typedef __int128 lll;
const int N=100+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
char str[N][N];
char vis[N][N];
char s[10]="yizhong";
int a[][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
bool  dfs(int x,int y,int c,int k){
    if(c==7){
        return 1;
    }else{
        int tx=x+a[k][0];
        int ty=y+a[k][1];
        if(0<=tx&&tx<n&&0<=ty&&ty<n&&str[tx][ty]==s[c]){
            if(dfs(tx,ty,c+1,k)){
                vis[tx][ty]=1;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    scanf("%d",&n);
    for(int i = 0; i < n; i++)  cin >> str[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(str[i][j]=='y'){
                 for(int k=0;k<8;k++){
                    int tx=i+a[k][0];
                    int ty=j+a[k][1];
                    if(0<=tx&&tx<n&&0<=ty&&ty<n&&str[tx][ty]=='i'){
                       if(dfs(tx,ty,2,k)){
                            vis[i][j]=1;
                            vis[tx][ty]=1;
                       }
                    }
                }
            }
        }
    }
    for(int i=0;i<n;i++){//输出结果
        for(int j=0;j<n;j++)
            if(vis[i][j]) printf("%c",str[i][j]);
            else printf("*");
        printf("\n");
    }
    //cout << "Hello world!" << endl;
    return 0;
}

 

全部评论

相关推荐

白火同学:先说结论,准大三不是特别好找实习,boss沟通300+没有实习是很正常的情况。一是暑期实习时间太短了,二是在这么多准大四都找不到实习,从实习时间和掌握技术层面,企业会优先看他们。 再说简历,其实985本+准大三到这水平的简历也很优秀了,要说的话,项目经历可以再优化一下,可以基本围绕采取STAR原则,分为项目概述、技术架构、技术亮点、实现结果,再发给AI润色一下。 最后说操作,准大三的话,如果想找实习那就多投,不过现在也7月中旬了,时间上已经略晚了。如果7月底实在找不到,也可以多刷点算法,多学点技术,这实习也不至于一定得有,当然有更好。
点赞 评论 收藏
分享
07-25 13:42
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务