3132321887 2022-08-29 15:54 采纳率: 100%
浏览 32
已结题

[蓝桥杯选拔赛2021.11]新冠病毒

[蓝桥杯选拔赛2021.11]新冠病毒
我用的是网上的代码
https://blog.csdn.net/my_names_Jacky/article/details/121596833
在devc++上没报错

img


但是OJ上报错了
能帮我看看吗
谢谢

Main.cc: In function 'void dfs(int, int)':
Main.cc:25:17: error: reference to 'next' is ambiguous
   25 |    int tx = x + next[i][0];
      |                 ^~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:66,
                 from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from Main.cc:1:
/usr/include/c++/9/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template constexpr _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
Main.cc:8:5: note:                 'int next [4][2]'
    8 | int next[4][2] = {
      |     ^~~~
Main.cc:26:17: error: reference to 'next' is ambiguous
   26 |    int ty = y + next[i][1];
      |                 ^~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:66,
                 from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from Main.cc:1:
/usr/include/c++/9/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template constexpr _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
Main.cc:8:5: note:                 'int next [4][2]'
    8 | int next[4][2] = {
      |     ^~~~
Main.cc: In function 'int change(char)':
Main.cc:7:1: warning: control reaches end of non-void function [-Wreturn-type]
    7 | }
      | ^

这是我的代码

#include<bits/stdc++.h>
using namespace std;
int change(char a){
    if(a == 'P')return 1;
    if(a == 'O')return 2;
    if(a == 'X')return 3;
}
int next[4][2] = {
                 {1, 0},
                 {-1,0},
                 {0, 1},
                 {0,-1}
                 };
int meet[100][100];
string p;
int n, m;
enum patient{
    normal,//正常人 
    old,   //旧病人 
    fresh  //新病人 
}used[100][100];
/*
'P' 1 -> 未接种新冠疫苗人员
'O' 2 -> 已接种新冠疫苗人员
'X' 3 -> 新冠患者
*/
//       初始x  初始y 
void dfs(int x, int y){
    if(meet[x][y] == change('X')){
        for(int i = 0;i < 4; i++){
            int tx = x + next[i][0];
            int ty = y + next[i][1];
            if(tx < 0 || tx > m || ty < 0 || ty > m || used[x][y] == 2)continue;
            if(meet[tx][ty] == change('P')){
                meet[tx][ty] = change('X');
                used[tx][ty] = fresh;
            }
        }
    }
    else return ;
}
int cnt(){
    int res = 0;
    for(int i = 1;i <= m; i++){
        for(int j = 1;j <= m; j++){
            if(meet[i][j] == change('X'))res++;
        }
    }
    return res;
}
void print(int num){
    for(int i = 1;i <= m; i++){
        for(int j = 1;j <= m; j++){
            cout << meet[i][j];
        }
        cout << endl;
    }
}
void c(){
    for(int i = 1;i <= m; i++){
        for(int j = 1;j <= m; j++){
            if(used[i][j] != 0)used[i][j] = old;
        }
    }
}
int main(){
    cin >> n >> m;
    for(int i = 1;i <= m; i++){
        cin >> p;
        for(int j = 1;j <= m; j++){
            meet[i][j] = change(p[j - 1]);
            if(p[j-1] == 'X')used[i][j] = old;
            else used[i][j] = normal;
        }
    }
    for(int i = 1;i <= n; i++){
        c();
        for(int j = 1;j <= m;j++){
            for(int k = 1;k <= m; k++){
                dfs(j, k);
            }
        }
        //print(i);
    }
    cout << cnt();
}
  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2022-08-29 16:42
    关注

    next数组换个名称吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月16日
  • 已采纳回答 9月8日
  • 创建了问题 8月29日

悬赏问题

  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启