[蓝桥杯选拔赛2021.11]新冠病毒
我用的是网上的代码
https://blog.csdn.net/my_names_Jacky/article/details/121596833
在devc++上没报错
但是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();
}