实验二
来源:互联网 发布:4g 网络手机 编辑:程序博客网 时间:2024/06/05 09:05
1.
#include<bits/stdc++.h>
using namespace std;int main()
{
int n,a;
queue<int> q;
stack<int> s;
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%d",&a);
q.push(a);
}
while(!q.empty())
{
s.push(q.front());
q.pop();
}
while(!s.empty())
{
q.push(s.top());
s.pop();
}
while(!q.empty())
{
printf("%d ",q.front());
q.pop();
}
return 0;
}
3.
//dfs
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000;
char mp[maxn][maxn];//1代表有障碍,S为起点,E为终点
bool vis[maxn][maxn];//1表示已被访问
int n,m;
int flag;
bool judge(int x, int y)
{
if(x>0 && x<=n && y>0 && y<=m && !vis[x][y] && mp[x][y] != '1')
return true;
return false;
}
void dfs(int x, int y)
{
if(mp[x][y] == 'E')
{
flag = 1;
return ;
}
vis[x][y] = 1;
for(int i = -1; i <= 1; i++)
for(int j = -1; j <= 1; j++)
{
int x1 = x + i;
int y1 = y + j;
if(judge(x1,y1))
dfs(x1,y1);
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(vis,0,sizeof(vis));
flag = 0;
int posx,posy;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
cin>>mp[i][j];
if(mp[i][j] == 'S')
{
posx = i;
posy = j;
}
}
dfs(posx,posy);
if(flag)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
- 实验二 单链表实验
- 【实验二】串口实验
- 实验一&实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- 实验二
- Java中POI操作Excel常用方法
- 深度解读互联网+供应链金融八大模式
- PAT考试乙级1011(C语言实现)
- 替换字符串中连续出现的指定字符串
- [BZOJ1103][POI2007]大都市meg(树状数组维护树上差分)
- 实验二
- http协议学习-基础概念篇
- CSS代码(五):一种段落首行缩进字符的解决办法
- idea使用
- JAVA 实现AES加密的两种方法
- MyBatis框架
- Idea 环境Tomcat打不开web项目的问题记录 404
- 本地Laravel更新到线上服务器(10月30日),以及出现的意外情形
- jQuery返回顶部插件-toTop