Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
121191 刘星辰liuxingchen 计算机病毒 C++ 通过 100 3 MS 368 KB 1451 2024-01-21 15:45:37

Tests(10/10):


#include<bits/stdc++.h> using namespace std; int n; char c[110][110]; int used[110][110]; int m; int a[110][110]; struct point { int x; int y; int now; }; struct p { int x; int y; }; vector<p> path; int bx[4]={0,0,1,-1}; int by[4]={1,-1,0,0}; bool check(int x,int y,int t) { if(x<1 || x>n || y<1 || y>n) { return 0; } if(used[x][y]==1 && t>=a[x][y] || used[x][y]==-1) { return 0; } return 1; } void bfs(int tx,int ty) { queue<point> q; q.push({tx,ty,0}); while(!q.empty()) { point t; t=q.front(); q.pop(); for(int i=0;i<4;i++) { int xx=t.x+bx[i]; int yy=t.y+by[i]; if(check(xx,yy,t.now+1)==1) { used[xx][yy]=1; a[xx][yy]=t.now+1; if(t.now+1!=m) { q.push({xx,yy,t.now+1}); } } } } return ; } int sum; int main() { cin>>n; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { cin>>c[i][j]; if(c[i][j]=='@') { path.push_back({i,j}); used[i][j]=1; sum++; } else if(c[i][j]=='#') { used[i][j]=-1; a[i][j]=INT_MAX; } } } cin>>m; for(int i=0;i<path.size();i++) { bfs(path[i].x,path[i].y); } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { // cout<<setw(11)<<a[i][j]; if(a[i][j]!=INT_MAX && a[i][j]!=0) { sum++; } } // cout<<endl; } cout<<sum; return 0; } /* 5 4321# *#1@1 *#@12 #2123 43234 4 */


测评信息: