弹指间计算机协会 X Five Pines Robomaster实验室 考核题面与题解(三)

简介: 弹指间计算机协会 X Five Pines Robomaster实验室 考核题面与题解

Sample Input 1

3 
2 4 1 
0 0 1 
0 0 3 
2 5 1 
0 0 1 
0 0 4 
2 5 2 
0 0 2 
2 0 4

Sample Output 1

Yes
No
Yes

Hint

第一组数据,由奶酪的剖面图可见:

第一个空洞在 ( 0 , 0 , 0 )与下表面相切;

第二个空洞在 ( 0 , 0 , 4 ) 与上表面相切;

两个空洞在 ( 0 , 0 , 2 ) 相切。

输出 Yes

第二组数据,由奶酪的剖面图可见:

两个空洞既不相交也不相切。

输出 No

第三组数据,由奶酪的剖面图可见:

两个空洞相交,且与上下表面相切或相交。

输出 Yes

【数据规模与约定】

image.png


题解

建图,设0号点为起点,n+1号点为终点。将每个洞视为图中的点。若洞高度绝对值小于半径r,则起点连到该点。若洞高度大于hr,则该点连到终点。若距离小于半径的两倍,则两个洞所代表的点连一条边。建图完成后,dfs

代码

#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
typedef long long ll;
vector<int> G[1005];
double ball[1005][4];
bool st[1005];
void dfs(int i){
  st[i]=1;
  for(auto node:G[i]){
    if (!st[node])
      dfs(node);
  }
}
signed main(){
  freopen("res.in","r",stdin);
  freopen("res.out","w",stdout);
  int t;
  cin>>t;
  while(t--){
    memset(ball,0,sizeof ball);
    memset(st,0,sizeof st);
    int n;
    double h,r;
    cin>>n>>h>>r;
    for(int i=0;i<=n+1;i++)
      G[i].clear(); 
    for(int i=1;i<=n;i++){
      cin>>ball[i][1]>>ball[i][2]>>ball[i][3];
    }
    for(int i=1;i<=n;i++){
      if (ball[i][3]<=r){
        G[0].push_back(i);//0号点为起点,底边
        G[i].push_back(0);
      }
      if (ball[i][3]>=h-r){
        G[n+1].push_back(i);//n+1号点为终点 
        G[i].push_back(n+1);
      }
      for(int j=i+1;j<=n;j++){
        double sqrdst=(ball[i][1]-ball[j][1])*(ball[i][1]-ball[j][1])
              +(ball[i][2]-ball[j][2])*(ball[i][2]-ball[j][2])
              +(ball[i][3]-ball[j][3])*(ball[i][3]-ball[j][3]);
        if (sqrdst<=4*r*r){
          G[i].push_back(j);
          G[j].push_back(i);
        }
      }
    }
    dfs(0);
    if (st[n+1])
      cout<<"Yes\n";
    else
      cout<<"No\n";
  }
}

机器人搬重物

Description

image.png

Output

一个整数,表示机器人完成任务所需的最少时间。如果无法到达,输出1

Sample Input 1

9 10
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 1 0
7 2 2 7 S

Sample Output 1

12

题解

image.png

代码

#include<iostream>
#include<queue>
#include<cstring>
#include<map>
#include<iomanip>
using namespace std;
struct posd{
  int x, y, d;
};
int collidx[4] = { -1, 0,-1,0 };//障碍物
int collidy[4] = { -1,-1, 0,0 };
int dx[4] = { -1,1,0,0 };
int dy[4] = { 0,0,-1,1 };
int dist[55][55][4];//0 北 1南 2西 3东
map<char, int> c2i = {{'N',0},{'S',1},{'W',2},{'E',3}};
int ditu[55][55];
int n, m;
bool collide(int x, int y) {
  if (x == 0 || y == 0 || x >= n || y >= m)
    return true;
  for (int k = 0;k < 4;k++) {
    int tx = x + collidx[k];
    int ty = y + collidy[k];
    if (ditu[tx][ty] == 1)
      return true;
  }
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0;i < n;i++)
    for (int j = 0;j < m;j++)
      cin >> ditu[i][j];
  int startx, starty, endx, endy;
  char startd;
  cin >> startx >> starty >> endx >> endy;
  cin >> startd;
  memset(dist, 0x3f3f3f3f, sizeof dist);
  queue<posd> q;
  q.push({ startx,starty,c2i[startd] });
  dist[startx][starty][c2i[startd]] = 0;
  while (!q.empty()) {
    auto p= q.front();
    q.pop();
    if (p.d == 0 || p.d == 1) {//从南北转到东西
      if (dist[p.x][p.y][2] == 0x3f3f3f3f) {
        dist[p.x][p.y][2] = dist[p.x][p.y][p.d] + 1;
        q.push({ p.x,p.y,2 });
      }
      if (dist[p.x][p.y][3] == 0x3f3f3f3f) {
        dist[p.x][p.y][3] = dist[p.x][p.y][p.d] + 1;
        q.push({ p.x,p.y,3 });
      }
    }
    if (p.d == 2 || p.d == 3) {//从东西转到南北
      if (dist[p.x][p.y][0] == 0x3f3f3f3f) {
        dist[p.x][p.y][0] = dist[p.x][p.y][p.d] + 1;
        q.push({ p.x,p.y,0 });
      }
      if (dist[p.x][p.y][1] == 0x3f3f3f3f) {
        dist[p.x][p.y][1] = dist[p.x][p.y][p.d] + 1;
        q.push({ p.x,p.y,1 });
      }
    }
    //往对应方向走1/2/3步
    int tx = p.x, ty = p.y;
    for (int _ = 0;_ <3;_++) {
      tx +=dx[p.d];
      ty +=dy[p.d];
      if (collide(tx, ty))
        break;
      if (dist[tx][ty][p.d] != 0x3f3f3f3f)
        continue;
      dist[tx][ty][p.d] = dist[p.x][p.y][p.d] + 1;
      q.push({ tx,ty,p.d });
    }
  }
  int res = 0x3f3f3f3f;
  for (int k = 0;k < 4;k++)
    res = min(res, dist[endx][endy][k]);
    if (res==0x3f3f3f3f)
        cout<<-1;
    else 
    cout << res << endl;
}
目录
相关文章
|
算法
孜孜不倦,上下求索——悼念原复旦大学计算机学院朱洪教授
上海交通大学软件学院副教授李停舟发微博称,原复旦大学计算机系教授朱洪1月27日逝世。朱洪教授是我国知名算法理论专家,也是复旦大学计算机科学技术学院40多年发展的亲历者和建设者。本文将朱洪教授在复旦工作的经历进行编辑,以念逝者。
3519 0
|
2月前
|
网络协议 安全 Linux
【题目】【网络系统管理】2019年全国职业技能大赛高职组计算机网络应用赛项H卷
【题目】【网络系统管理】2019年全国职业技能大赛高职组计算机网络应用赛项H卷
【题目】【网络系统管理】2019年全国职业技能大赛高职组计算机网络应用赛项H卷
|
2月前
|
网络协议 安全 网络安全
【题目】【网络系统管理】2022年江苏省职业院校技能大赛 高职竞赛样题
【题目】【网络系统管理】2022年江苏省职业院校技能大赛 高职竞赛样题
【题目】【网络系统管理】2022年江苏省职业院校技能大赛 高职竞赛样题
|
2月前
|
网络协议 安全 数据安全/隐私保护
【题目】【网络系统管理】2022年甘肃省职业院校技能大赛-网络构建-试卷
【题目】【网络系统管理】2022年甘肃省职业院校技能大赛-网络构建-试卷
【题目】【网络系统管理】2022年甘肃省职业院校技能大赛-网络构建-试卷
|
2月前
|
安全 网络安全 测试技术
【题目】2023年国赛信息安全管理与评估正式赛任务书-模块3 CTF
【题目】2023年国赛信息安全管理与评估正式赛任务书-模块3 CTF
【题目】2023年国赛信息安全管理与评估正式赛任务书-模块3 CTF
|
2月前
|
安全 Linux 网络安全
2024年山东省职业院校技能大赛中职组 “网络安全”赛项竞赛试题-B-CTF夺旗与攻击
模块C和D是CTF夺旗比赛,分别侧重攻击和防御。作为渗透测试工程师,你需要在靶机(Linux/Windows)上找寻多种漏洞,如命令注入、文件上传、文件包含、远程代码执行和缓冲区溢出,以获取权限。同时,注意不能攻击裁判服务器,违者将被罚离场。提交靶机的唯一标识flag值并按规则加分。模块D中,你需要在堡垒服务器上发现并修复同样类型的漏洞,保证服务可用性,制作系统防御报告,所有截图需清晰,文件以PDF格式保存提交。
30 0
|
2月前
|
安全 Linux 网络安全
2024年山东省职业院校技能大赛中职组 “网络安全”赛项竞赛试题-B
网络安全模块A,涉及Windows和Linux服务器的安全加固。任务包括:设置强密码和登录策略,如账户锁定和最小密码长度;禁止未加密密码传输和来宾账户访问;关闭系统时清除内存页面文件,禁止无登录关机,限制驱动器访问;确保流量完整性,如SSL访问和SSH证书登录;事件监控,如应用日志存档;服务加固,如SSH禁止root远程登录,VSFTPD超时设置,IIS防止文件枚举和关闭WebDAV;以及防火墙策略,如限制DNS转发,禁止ping,禁用端口和MAC地址,限制IP碎片和SSH连接。所有更改需截图并按指定格式保存提交。
32 0
|
2月前
|
安全 JavaScript 前端开发
第十六届山东省职业院校技能大赛中职组 “网络安全”赛项竞赛试题—B模块安全事件响应/网络安全数据取证/应用安全
该内容描述了一次网络安全演练,包括七个部分:Linux渗透提权、内存取证、页面信息发现、数字取证调查、网络安全应急响应、Python代码分析和逆向分析。参与者需在模拟环境中收集Flag值,涉及任务如获取服务器信息、提权、解析内存片段、分析网络数据包、处理代码漏洞、解码逆向操作等。每个部分都列出了若干具体任务,要求提取或生成特定信息作为Flag提交。
68 0
|
9月前
|
安全 测试技术 网络安全
2023年江西省赣州市技能大赛 网络安全竞赛试题任务书
2023年江西省赣州市技能大赛 网络安全竞赛试题任务书
117 0
C国演义 [第三章]
C国演义 [第三章]