标签:不能 sub als bool node nod style subject const
1 class Solution { 2 public: 3 bool judge(int shreshold,int rows,int cols){ 4 int ans=0; 5 while (rows){ 6 ans=ans+rows%10; 7 rows/=10; 8 } 9 while (cols){ 10 ans=ans+cols%10; 11 cols/=10; 12 } 13 if (shreshold>=ans) 14 return true; 15 return false; 16 } 17 void bfs(int shreshold,int rows,int cols,int &ans){ 18 const int m=rows,n=cols; 19 bool vis[m+10][n+10]; 20 for (int i=0;i<m;i++) 21 for (int j=0;j<n;j++) vis[i][j]=true; 22 vis[0][0]=false; 23 struct s{ 24 int x,y; 25 }mp; 26 int dir[4][2]={1,0,0,1,-1,0,0,-1}; 27 queue<s>q; 28 while (!q.empty()) q.pop(); 29 mp.x=mp.y=0; 30 q.push(mp); 31 while (!q.empty()){ 32 s node,temp=q.front(); 33 q.pop(); 34 for (int k=0;k<4;k++){ 35 node.x=temp.x+dir[k][0]; 36 node.y=temp.y+dir[k][1]; 37 if (node.x>=0&&node.x<rows&&node.y>=0&&node.y<cols&&vis[node.x][node.y]&&judge(shreshold, node.x, node.y)){ 38 q.push(node); 39 vis[node.x][node.y]=false; 40 ans++; 41 } 42 } 43 } 44 return ; 45 } 46 int movingCount(int threshold, int rows, int cols) 47 { 48 if (threshold<0||rows<0||cols<0) return 0; 49 int ans=1; 50 bfs(threshold,rows,cols,ans); 51 return ans; 52 } 53 };
很常规的题目
标签:不能 sub als bool node nod style subject const
原文地址:https://www.cnblogs.com/q1204675546/p/13362545.html