当前位置:网站首页>Naoqi robot summary 26
Naoqi robot summary 26
2022-07-05 23:25:00 【hiyaaa】
Basic algorithm
#include<bits/stdc++.h>
using namespace std;
const int N=1100;
int size[N];
char s[N][N];
int vis[N][N];
int dx[8]={0,1,0,-1,-1,1,1,-1};
int dy[8]={1,0,-1,0,1,1,-1,-1};
int m,cnt;
int a[N],b[N],tot,tot1;
void dfs(int x,int y,int &ans,int k)
{// For every cannon attacked , So it's centered 3*3 The squares will be affected , So find the connected block , The number of each connected block , And the number of cannons in each connected block .
if(s[x][y]=='.') return ;
vis[x][y]=true;
for(int i=0;i<8;i++)
{
int xx=dx[i]+x;
int yy=dy[i]+y;
if(xx<k||xx>=k+4||yy<0||y>=m||vis[xx][yy]) continue;
vis[xx][yy]=true;
if(s[xx][yy]=='*') ans++;
dfs(xx,yy,ans,k);
}
}
int main()
{
cin>>m;
for(int i=0;i<8;i++) cin>>s[i];
for(int i=0;i<4;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='*'&&!vis[i][j])
{
cnt=1;
dfs(i,j,cnt,0);
a[++tot]=cnt;
}
}
}
for(int i=4;i<8;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='*'&&!vis[i][j])
{
cnt=1;
dfs(i,j,cnt,4);
b[++tot1]=cnt;
}
}
}
if(tot1<tot) cout<<-1<<endl;
else
{
sort(b+1,b+1+tot1);
int ans=0;
for(int i=tot;i<=tot1;i++) ans+=b[i];
cout<<ans<<endl;
}
}
#include <bits/stdc++.h>
const int maxn = 510;
const int MaxN = 0x3f3f3f3f;
const int MinN = 0xc0c0c00c;
typedef long long ll;
const int mod = 100000000;
using namespace std;
char a[maxn][maxn];
bool visited[maxn][maxn];
bool flag=false;
int n,m;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void dfs(int x,int y){
if(a[x][y]=='E'){
flag=true;
return ;
}
if(flag==true) return ;
for(int i=0;i<4;i++){
int nx=x+dx[i];
int ny=y+dy[i];
if((a[nx][ny]=='.'||a[nx][ny]=='E')&&!visited[nx][ny]){
visited[nx][ny]=true;
dfs(nx,ny);
}
}
}
int main()
{
while(cin>>n>>m){
memset(visited,false,sizeof(visited));
memset(a,-1,sizeof(a));
for(int i=1;i<=n;i++){
scanf("%s",a[i]+1);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]=='S'){
flag=false;
visited[i][j]=true;
dfs(i,j);
break;
}
}
}
if(flag) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
边栏推荐
- Detailed explanation of pointer and array written test of C language
- UVA – 11637 Garbage Remembering Exam (组合+可能性)
- Development specification: interface unified return value format [resend]
- Go language implementation principle -- map implementation principle
- 开关电源Buck电路CCM及DCM工作模式
- Dynamic memory management (malloc/calloc/realloc)
- Creative mode 1 - single case mode
- Realize reverse proxy client IP transparent transmission
- Mathematical formula screenshot recognition artifact mathpix unlimited use tutorial
- Idea rundashboard window configuration
猜你喜欢
Southeast Asia e-commerce guide, how do sellers layout the Southeast Asia market?
Three. Js-01 getting started
Use of grpc interceptor
2:第一章:认识JVM规范1:JVM简介;
Commonly used probability distributions: Bernoulli distribution, binomial distribution, polynomial distribution, Gaussian distribution, exponential distribution, Laplace distribution and Dirac delta d
Registration and skills of hoisting machinery command examination in 2022
Expectation, variance and covariance
[original] what is the core of programmer team management?
Data type, variable declaration, global variable and i/o mapping of PLC programming basis (CoDeSys)
动态规划 之 打家劫舍
随机推荐
698. 划分为k个相等的子集 ●●
Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
CorelDRAW plug-in -- GMS plug-in development -- new project -- macro recording -- VBA editing -- debugging skills -- CDR plug-in (2)
Go language implementation principle -- map implementation principle
秒杀系统的设计与实现思路
Pyqt control part (I)
2: Chapter 1: understanding JVM specification 1: introduction to JVM;
Live tiktok shop 2022 latest gameplay card slot overseas live e-commerce new traffic
Dynamic memory management (malloc/calloc/realloc)
开关电源Buck电路CCM及DCM工作模式
Common static methods of math class
Getting started stm32--gpio (running lantern) (nanny level)
Development specification: interface unified return value format [resend]
Data type, variable declaration, global variable and i/o mapping of PLC programming basis (CoDeSys)
February 13, 2022-4-symmetric binary tree
Negative sampling
Rethinking about MySQL query optimization
February 13, 2022 -5- maximum depth of binary tree
C# Linq Demo
CJ mccullem autograph: to dear Portland