#29750: 卡在92%下不去


bsbacon (波西米亞●陳傑)

學校 : 國立臺北大學
編號 : 138938
來源 : [27.53.163.71]
最後登入時間 :
2024-01-21 20:55:20
f149. 3. 炸彈偵測器 (Detector) -- 2020年6月TOI練習賽新手組 | From: [220.141.204.160] | 發表日期 : 2022-03-29 23:20

我找不出來哪裡出了問題,在後面40%有些對有些錯,請大神幫幫小弟找bug

#include <iostream>

using namespace std;

int main() {

int dx[8]={-1,-1,-1,0,0,1,1,1};

int dy[8]={-1,0,1,-1,1,-1,0,1};

int r,c,bombnum,detect,i,j,ter,time;

bool judge;

cin>>r>>c;

int land[r+2][c+2]={0};

bombnum=0;

detect=0;

for(i=1;i<=r;i++){

for(j=1;j<=c;j++){

cin>>land[i][j];

if(land[i][j]==1){

bombnum++;

}

}

}

for(i=1;i<=r;i++){

for(j=1;j<=c;j++){

if(land[i][j]==5){

judge=true;

ter=0;

for(time=0;time<8;time++){

if(land[i+dx[time]][j+dy[time]]==1){

ter++;

land[i+dx[time]][j+dy[time]]=0;

}

else if(land[i+dx[time]][j+dy[time]]==5){

judge=false;

break;

}

}

if(judge==true){

detect=detect+ter;

}

else{

continue;

}

}

}

}

cout<<detect<<" "<<bombnum-detect;

return 0;

}

 
#29752: Re:卡在92%下不去


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
f149. 3. 炸彈偵測器 (Detector) -- 2020年6月TOI練習賽新手組 | From: [27.53.33.71] | 發表日期 : 2022-03-30 08:17

1.

int land[r+2][c+2]={0};


2.

for(time=0;time<8;time++){

if(land[i+dx[time]][j+dy[time]]==1){

ter++;

land[i+dx[time]][j+dy[time]]=0;

}

else if(land[i+dx[time]][j+dy[time]]==5){

judge=false;

break;

}

}


1. VLA非標準C++的語法,雖然g++能支援,可是沒辦法這樣初始化二維VLA,可以用memset來初始化或是改用vector

2. 如果炸彈旁同時有失靈的偵測器,也有正常運作的偵測器,輸出會出錯,例如

3 3
5 1 5
5 0 0
0 0 0

可以改成兩個迴圈,先偵測旁邊是否有偵測器,再偵測炸彈

 
ZeroJudge Forum