当前位置:网站首页>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;
}
边栏推荐
- VS2010编写动态链接库DLL和单元测试,转让DLL测试的正确性
- UVA11294-Wedding(2-SAT)
- Hj16 shopping list
- Realize reverse proxy client IP transparent transmission
- YML configuration, binding and injection, verification, unit of bean
- C Primer Plus Chapter 9 question 9 POW function
- From the perspective of quantitative genetics, why do you get the bride price when you get married
- Go语言实现原理——锁实现原理
- February 13, 2022 -5- maximum depth of binary tree
- Multi view 3D reconstruction
猜你喜欢
Practice of concurrent search
3:第一章:认识JVM规范2:JVM规范,简介;
CJ mccullem autograph: to dear Portland
Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
Mathematical formula screenshot recognition artifact mathpix unlimited use tutorial
Neural structured learning - Part 3: training with synthesized graphs
Three. JS VR house viewing
How to design API return code (error code)?
The method and principle of viewing the last modification time of the web page
并查集实践
随机推荐
代码农民提高生产力
(4)UART應用設計及仿真驗證2 —— TX模塊設計(無狀態機)
Mathematical formula screenshot recognition artifact mathpix unlimited use tutorial
MySQL (2) -- simple query, conditional query
Golang code checking tool
When to use useImperativeHandle, useLayoutEffect, and useDebugValue
Data type, variable declaration, global variable and i/o mapping of PLC programming basis (CoDeSys)
Development specification: interface unified return value format [resend]
Detailed explanation of pointer and array written test of C language
动态规划 之 打家劫舍
C Primer Plus Chapter 9 question 9 POW function
Hj16 shopping list
Judge whether the binary tree is a complete binary tree
Data analysis - Thinking foreshadowing
February 13, 2022-4-symmetric binary tree
Leetcode buys and sells stocks
Negative sampling
Douban scoring applet Part-2
Introduction to JVM
2:第一章:认识JVM规范1:JVM简介;