当前位置:网站首页>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;
}
边栏推荐
- During its low-level period, this slave edge causes the instruction number to make a corresponding model
- [untitled] I is circularly accumulated under certain conditions. The condition is usually the length of the loop array. When it exceeds the length, the loop will stop. Because the object cannot judge
- Complete Binary Tree
- [Niuke discussion area] Chapter 7: building safe and efficient enterprise services
- Flexible array and common problems
- JVM Part 1: memory and garbage collection -- runtime data area 4 - program counter
- pyside2____1.安装和案列
- Could not autowire.No beans of ‘userMapper‘ type found.
- B1028 人口普查
- How to store the startprocessinstancebykey method in acticiti in the variable table
猜你喜欢

Mysql表的约束

JVM Part 1: memory and garbage collection part 12 -- stringtable

Detailed description of polymorphism

JVM上篇:内存与垃圾回收篇十二--StringTable

JVM Part 1: memory and garbage collection part 14 -- garbage collector

34. Analyze flexible.js

Svn usage details

QT menu bar, toolbar and status bar

数据库设计——关系数据理论(超详细)

JVM上篇:内存与垃圾回收篇十四--垃圾回收器
随机推荐
B1027 打印沙漏
Installation and template setting of integrated development environment pychar
feign调用丢失请求头问题解决及原理分析
I've heard the most self disciplined sentence: those I can't say are silent
Machine learning overview
JVM上篇:内存与垃圾回收篇十一--执行引擎
知识点总结(一)
JVM Part 1: memory and garbage collection part 10 - runtime data area - direct memory
Card drawing program simulation
What should test / development programmers over 35 do? Many objective factors
Detailed description of polymorphism
Alphabetic order problem
精选用户故事|洞态在聚水潭的误报率几乎为0,如何做到?
How does the TCP server handle multiple client connections on one port (one-to-one or one to many)
JVM Part 1: memory and garbage collection part 8 - runtime data area - Method area
简化JDBC的MyBits框架
Flexible array and common problems
Basic operation of vim
Select user stories | the false positive rate of hole state in jushuitan is almost 0. How to do this?
Bean的生命周期&&依赖注入*依赖自动装配