_hjingc_ @ 2023-07-21 23:32:21
#include <cstdio>
#include <iostream>
#include <cstring>
using std::cout;
using std::cin;
int m;
int map[310][310],lx[310][310],vis[310][310],time[310][310];
//map中的数代表该位置多久后会因陨石袭击无法通行 若值为-1表示此地是安全地点
//lx表示此地多久后会落下流星 初值为0不影响 后面是按照陨石落点查询该数组
//vis值为1表示已经走过
//time表示到达此地所需的最短时间
const int dx[]={0,0,1,-1,0};
const int dy[]={1,-1,0,0,0};
struct Node{
int x,y;
}q[91000];
void bfs(int a,int b){
int head=0,tail=1;
q[1].x=a;q[1].y=b;vis[a][b]=1;
while(head<tail){
head++;
for(int i=0;i<4;i++){
int xx=q[head].x+dx[i];
int yy=q[head].y+dy[i];
//因为要在第一象限内所以横纵坐标必须都 >=0
if(map[xx][yy]==-1 && xx>0 && yy>0){
cout<<time[xx][yy];
return;
}
if(vis[xx][yy]!=1 && map[xx][yy]-time[xx][yy]>0 && xx>=0 && yy>=0){
//map[xx][yy]-time[xx][yy]表示到达此地时离陨石落下摧毁此地还有多久
tail++;
q[tail].x=xx;q[tail].y=yy;
vis[xx][yy]=1;
if(map[xx][yy]==-1 && xx>0 && yy>0){
cout<<time[xx][yy];
return;
}
}
}
}
printf("-1");
}
int main(){
scanf("%d",&m);
memset(map,-1,sizeof(map));
int x,y;
for(int i=1;i<=m;i++){
cin>>x>>y;
cin>>lx[x][y];
for(int j=0;j<=4;j++){
if(x+dx[j]<0 || y+dy[j]<0) continue;
if(map[x+dx[j]][y+dy[j]]>lx[x][y] || map[x+dx[j]][y+dy[j]]==-1)
map[x+dx[j]][y+dy[j]]=lx[x][y];
}
}//对map初始化
for(int i=0;i<=310;i++){
for(int j=0;j<=310;j++){
if(i!=0) time[i][j]=time[i-1][j]+1;
else if(j!=0) time[i][j]=time[i][j-1]+1;
}
}//对time初始化
bfs(0,0);
return 0;
}
/tmp/compiler_dl37x2bc/src:8:59: 错误:‘int time [310][310]’ redeclared as different kind of entity
8 | int map[310][310],lx[310][310],vis[310][310],time[310][310];
| ^
In file included from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/include-fixed/pthread.h:32,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/gthr-default.h:35,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/gthr.h:148,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/ext/atomicity.h:35,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/bits/ios_base.h:39,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/ios:42,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/ostream:38,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/iostream:39,
from /tmp/compiler_dl37x2bc/src:2:
/nix/store/7rfaw11na5ajdgwr55ffzwfibbrdpk8z-glibc-2.33-56-dev/include/time.h:75:15: 附注:previous declaration ‘time_t time(time_t*)’
75 | extern time_t time (time_t *__timer) __THROW;
| ^~~~
/tmp/compiler_dl37x2bc/src: 在函数‘void bfs(int, int)’中:
/tmp/compiler_dl37x2bc/src:29:18: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
29 | cout<<time[xx][yy];
| ^
/tmp/compiler_dl37x2bc/src:29:22: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
29 | cout<<time[xx][yy];
| ^
/tmp/compiler_dl37x2bc/src:32:44: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
32 | if(vis[xx][yy]!=1 && map[xx][yy]-time[xx][yy]>0 && xx>=0 && yy>=0){
| ^
/tmp/compiler_dl37x2bc/src:32:48: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
32 | if(vis[xx][yy]!=1 && map[xx][yy]-time[xx][yy]>0 && xx>=0 && yy>=0){
| ^
/tmp/compiler_dl37x2bc/src:32:36: 错误:操作数类型‘int’和‘time_t(time_t*) noexcept’ {aka ‘long int(long int*)’}对双目‘operator-’而言无效
32 | if(vis[xx][yy]!=1 && map[xx][yy]-time[xx][yy]>0 && xx>=0 && yy>=0){
| ~~~~~~~~~~~^~~~~~~~~~~~~
| | |
| int time_t(time_t*) noexcept {aka long int(long int*)}
/tmp/compiler_dl37x2bc/src:38:19: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
38 | cout<<time[xx][yy];
| ^
/tmp/compiler_dl37x2bc/src:38:23: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
38 | cout<<time[xx][yy];
| ^
/tmp/compiler_dl37x2bc/src: 在函数‘int main()’中:
/tmp/compiler_dl37x2bc/src:63:19: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
63 | if(i!=0) time[i][j]=time[i-1][j]+1;
| ^
/tmp/compiler_dl37x2bc/src:63:22: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
63 | if(i!=0) time[i][j]=time[i-1][j]+1;
| ^
/tmp/compiler_dl37x2bc/src:63:32: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
63 | if(i!=0) time[i][j]=time[i-1][j]+1;
| ^
cc1plus: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
/tmp/compiler_dl37x2bc/src:63:35: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
63 | if(i!=0) time[i][j]=time[i-1][j]+1;
| ^
/tmp/compiler_dl37x2bc/src:63:36: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
63 | if(i!=0) time[i][j]=time[i-1][j]+1;
| ~~~~~~~~~~~~^~
/tmp/compiler_dl37x2bc/src:63:23: 错误:向只读位置‘*(time + (((sizetype)i) + ((sizetype)j)))’赋值
63 | if(i!=0) time[i][j]=time[i-1][j]+1;
| ~~~~~~~~~~^~~~~~~~~~~~~~~
/tmp/compiler_dl37x2bc/src:64:24: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
64 | else if(j!=0) time[i][j]=time[i][j-1]+1;
| ^
/tmp/compiler_dl37x2bc/src:64:27: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
64 | else if(j!=0) time[i][j]=time[i][j-1]+1;
| ^
/tmp/compiler_dl37x2bc/src:64:35: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
64 | else if(j!=0) time[i][j]=time[i][j-1]+1;
| ^
/tmp/compiler_dl37x2bc/src:64:40: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
64 | else if(j!=0) time[i][j]=time[i][j-1]+1;
| ^
cc1plus: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
/tmp/compiler_dl37x2bc/src:64:41: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
64 | else if(j!=0) time[i][j]=time[i][j-1]+1;
| ~~~~~~~~~~~~^~
/tmp/compiler_dl37x2bc/src:64:28: 错误:向只读位置‘*(time + (((sizetype)i) + ((sizetype)j)))’赋值
64 | else if(j!=0) time[i][j]=time[i][j-1]+1;
| ~~~~~~~~~~^~~~~~~~~~~~~~~
by Kedit2007 @ 2023-07-22 00:42:38
time
是一个已经存在的函数,重名了。
部分报错翻译:
redeclared as different kind of entity
:以其他类型重定义。
附注:previous declaration ‘time_t time(time_t*)’...
:先前的定义为:'time_t time(...)
。
可以自己先把报错翻译一下。
by _hjingc_ @ 2023-07-22 23:35:46
@Kedit2007
谢谢大佬(´▽`ʃ♡ƪ)
解决了!
by _hjingc_ @ 2023-07-23 00:23:12
@Kedit2007
大佬,还有问题求教(;′⌒`)
这个安全地点包不包含坐标轴上的点啊?
从样例上看是不包括的
但是测试点 3 如果不包括坐标轴的话应该是 -1
可是测试点 3 的答案是 3
输入 #测试点3
5
0 0 2
3 0 0
1 2 5
2 2 4
1 4 4
输出 #测试点3
3
输入 #样例
4
0 0 2
2 1 2
1 1 2
0 3 5
输出 #样例
5