蒟蒻求救QAQ

P1789 【Mc生存】插火把

------------ @[editcom2000](/user/84379) ------------ 判断越界,附上我的代码: ```cpp #include <bits/stdc++.h> using namespace std; struct bit{ int x; int y; }; bool check(int x,int y,int n){ if(x<0 || x>=n || y<0 || y>=n)return false; return true; } int main(){ int n,m,k;cin>>n>>m>>k;bool map[n][n];memset(map,1,sizeof(map)); bit hb[m],ys[k];for(int i=0;i<m;i++)cin>>hb[i].x>>hb[i].y;for(int i=0;i<k;i++)cin>>ys[i].x>>ys[i].y; for(int i=0;i<m;i++){ if(check(--hb[i].x-2,--hb[i].y,n))map[hb[i].x-2][hb[i].y]=false; if(check(hb[i].x-1,hb[i].y-1,n))map[hb[i].x-1][hb[i].y-1]=false; if(check(hb[i].x-1,hb[i].y,n))map[hb[i].x-1][hb[i].y]=false; if(check(hb[i].x-1,hb[i].y+1,n))map[hb[i].x-1][hb[i].y+1]=false; if(check(hb[i].x,hb[i].y-2,n))map[hb[i].x][hb[i].y-2]=false; if(check(hb[i].x,hb[i].y-1,n))map[hb[i].x][hb[i].y-1]=false; if(check(hb[i].x,hb[i].y,n))map[hb[i].x][hb[i].y]=false; if(check(hb[i].x,hb[i].y+1,n))map[hb[i].x][hb[i].y+1]=false; if(check(hb[i].x,hb[i].y+2,n))map[hb[i].x][hb[i].y+2]=false; if(check(hb[i].x+1,hb[i].y-1,n))map[hb[i].x+1][hb[i].y-1]=false; if(check(hb[i].x+1,hb[i].y,n))map[hb[i].x+1][hb[i].y]=false; if(check(hb[i].x+1,hb[i].y+1,n))map[hb[i].x+1][hb[i].y+1]=false; if(check(hb[i].x+2,hb[i].y,n))map[hb[i].x+2][hb[i].y]=false; } for(int i=0;i<k;i++){ ys[i].x--;ys[i].y--; for(int j=-2;j<=2;j++)for(int l=-2;l<=2;l++)if(check(ys[i].x+j,ys[i].y+l,n))map[ys[i].x+j][ys[i].y+l]=false; } int sum=0;for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(map[i][j])sum++; cout<<sum; return 0; } ```
by ihesro @ 2020-06-27 23:16:04


|