当前位置:网站首页>2022 Zhengzhou light industry Freshmen's competition topic - I won't say if I'm killed
2022 Zhengzhou light industry Freshmen's competition topic - I won't say if I'm killed
2022-07-27 05:20:00 【Ye Chen】
7-5 Kill me without saying ! (15 branch )
stem : What is the best secret code ? yes “ Kill me without saying !” such , Even if the pig teammate who helped us transmit the secret code was caught by the enemy and tortured , We don't have to worry about divulging secrets .
Now improve a little , We put “ Kill me without saying ” The first letter of Pinyin “DSWYBS” Hidden in a matrix , On behalf of “ hit ” The letter of D And representatives “ say ” The letter of S The sum of the subscripts in the row is the password .
For a given matrix , Please judge whether there is “DSWYBS”, If there is , Give the subscript of the first and last two letters and calculate the password ; without , Print a row “DSWYBS”.
Be careful :
- If hidden “DSWYBS”, Then this string of letters must be along the line 、 Column or oblique 45 Degrees in order .
- The title ensures that the input matrix contains at most one string “DSWYBS”.
- The subscript in the upper left corner of the matrix is (0,0).
- Case sensitive .
- The title ensures that the input matrix does not contain such an arrangement ( namely : have only DSWYB Five letters , But the letters B And S adjacent , It can be made up of DSWYBS Permutation ) :
DSB
WY
Input format :
The first line gives two integers M、N( No more than 15、 Not less than 4), Next M That's ok , Each row has N Letters or numbers , End with a new line .
Output format :
If there is “DSWYBS”, Then output three lines , The first and second lines are initials respectively D Subscript and final letter of S The subscript , First subscript then column subscript , Separated by a space . The third line gives the sum of the four subscript values of two letters .
If the string of letters is not hidden , Then print a line “DSWYBS”
sample input
8 10
0x00z000d0
00aD00s000
00b0SWk000
000wcY000s
00000B0000
0000S00000
0000000000
0000000000
sample output
1 3
5 4
13
sample input
5 5
12345
adswa
54321
dswys
aaaaa
sample output
DSWYBS
Topic analysis :
- dfs Traverse
The code is as follows :
#include<bits/stdc++.h>
using namespace std;
string s="DSWYBS";
int m,n;
char a[16][16];
bool vis[16][16]={false};
bool flag=false;
int fx,fy,lx,ly;
void dfs(int x,int y,int count){
// As of condition
if(flag==true||count==6){
flag=true;
lx=x;
ly=y;
return;
}
// Traversing candidate nodes
for(int i=x-1;i<=x+1;i++){
for(int j=y-1;j<=y+1;j++){
// Screening
if(i>=0&&i<m&&j>=0&&j<n){
if(!vis[i][j]&&a[i][j]==s[count]){
// cout<<count<<" "<<s[count]<<" "<<i<<" "<<j<<endl;
vis[i][j]=true;
dfs(i,j,count+1);
vis[i][j]=false;
}
}
}
}
}
int main(){
// freopen("in.txt","r",stdin);
cin>>m>>n;
getchar();
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(!vis[i][j]&&a[i][j]==s[0]){
vis[i][j]=true;
int x=fx;
int y=fy;
fx=i;
fy=j;
dfs(i,j,1);
if(flag==true){
break;
}
fx=x;
fy=y;
vis[i][j]=false;
}
}
}
if(flag==true){
int sum=0;
sum=fx+fy+lx+ly;
cout<<fx<<' '<<fy<<endl<<lx<<' '<<ly<<endl<<sum;
}else{
cout<<"DSWYBS";
}
return 0;
}
边栏推荐
- Detailed description of binary search tree
- 1、 MySQL Foundation
- JVM Part 1: memory and garbage collection part 11 -- execution engine
- Acticiti中startProcessInstanceByKey方法在variable表中的如何存储
- pyside2____1.安装和案列
- B1031 查验身份证
- [optical flow] - data format analysis, flowwarp visualization
- 节流函数的demo——正则表达式匹配
- How to store the startprocessinstancebykey method in acticiti in the variable table
- Two dimensional array summation exercise
猜你喜欢

JVM Part 1: memory and garbage collection part 5 -- runtime data area virtual machine stack

Install pyGame

JVM上篇:内存与垃圾回收篇--运行时数据区四-程序计数器

Dialog introduction

Typescript details

Installation and template setting of integrated development environment pychar

精选用户故事|洞态在聚水潭的误报率几乎为0,如何做到?

JVM上篇:内存与垃圾回收篇六--运行时数据区-本地方法&本地方法栈

Gradio quickly builds ml/dl Web Services

2、 MySQL advanced
随机推荐
JVM Part 1: memory and garbage collection part 3 - runtime data area - overview and threads
A math problem cost the chip giant $500million
微淼联合创始人孙延芳:以合规为第一要义,做财商教育“正规军”
Complete Binary Tree
JDBC API 详解
辗转相除法
Solution and principle analysis of feign call missing request header
Could not autowire.No beans of ‘userMapper‘ type found.
How to test the payment process?
LocalDateTime和ZonedDateTime
JVM上篇:内存与垃圾回收篇九--运行时数据区-对象的实例化,内存布局与访问定位
The difference between strlen and sizeof
来自“飞人”乔丹的启示!奥尼尔开启的另一个“赛场”
精选用户故事|洞态在聚水潭的误报率几乎为0,如何做到?
2、 MySQL advanced
Mysql表的约束
Introduction to dynamic memory functions (malloc free calloc realloc)
素数筛选(埃氏筛法,区间筛法,欧拉筛法)
MQ message queue is used to design the high concurrency of the order placing process, the generation scenarios and solutions of message squeeze, message loss and message repetition
节流函数的demo——正则表达式匹配