当前位置:网站首页>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;
}
边栏推荐
- golang代码检查工具
- yate.conf
- Registration of Electrical Engineering (elementary) examination in 2022 and the latest analysis of Electrical Engineering (elementary)
- YML configuration, binding and injection, verification, unit of bean
- Debian 10 installation configuration
- Code farmers to improve productivity
- openresty ngx_ Lua request response
- 2022 R2 mobile pressure vessel filling review simulation examination and R2 mobile pressure vessel filling examination questions
- Matlab smooth curve connection scatter diagram
- Judge whether the binary tree is a complete binary tree
猜你喜欢
Data type, variable declaration, global variable and i/o mapping of PLC programming basis (CoDeSys)
芯源&立创EDA训练营——无刷电机驱动
Go语言实现原理——Map实现原理
动态规划 之 打家劫舍
Go语言实现原理——锁实现原理
698. 划分为k个相等的子集 ●●
Expectation, variance and covariance
LabVIEW打开PNG 图像正常而 Photoshop打开得到全黑的图像
TypeError: this. getOptions is not a function
2022 G3 boiler water treatment simulation examination and G3 boiler water treatment simulation examination question bank
随机推荐
派对的最大快乐值
Leecode learning notes
C Primer Plus Chapter 9 question 10 binary conversion
MySQL (1) -- related concepts, SQL classification, and simple operations
Using LNMP to build WordPress sites
Spécifications techniques et lignes directrices pour la sélection des tubes TVS et ESD - Recommandation de jialichuang
How to enable relationship view in phpMyAdmin - how to enable relationship view in phpMyAdmin
White hat talks about web security after reading 2
Use of metadata in golang grpc
UVA – 11637 garbage remembering exam (combination + possibility)
Attacking technology Er - Automation
424. 替换后的最长重复字符 ●●
VS2010编写动态链接库DLL和单元测试,转让DLL测试的正确性
C Primer Plus Chapter 9 question 9 POW function
Rethinking about MySQL query optimization
UVA11294-Wedding(2-SAT)
Difference between out of band and in band
2: Chapter 1: understanding JVM specification 1: introduction to JVM;
开关电源Buck电路CCM及DCM工作模式
二叉树递归套路总结