sb题(滑雪sb版)
1 #include <bits/stdc++.h> 2 #define LL long long 3 #define lowbit(x) x&(-x) 4 #define inf 0x3f3f3f3f 5 using namespace std; 6 inline int ra() 7 { 8 int x=0,f=1; char ch=getchar(); 9 while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();} 10 while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();} 11 return x*f; 12 } 13 int f[1005][1005],n,a[1005][1005],m,ans; 14 bool vis[1005][1005]; 15 int xx[]={0,0,0,1,-1},yy[]={0,1,-1,0,0}; 16 void dfs(int x, int y) 17 { 18 if (f[x][y]) return; else f[x][y]=1; 19 for (int i=1; i<=4; i++) 20 { 21 int _x=x+xx[i],_y=y+yy[i]; 22 if (_x<1 || _x>n || _y<1 || _y>n || a[x][y]<=a[_x][_y] || vis[_x][_y]) continue; 23 dfs(_x,_y); 24 f[x][y]=max(f[x][y],f[_x][_y]+1); 25 } 26 ans=max(ans,f[x][y]); 27 } 28 int get_ans() 29 { 30 ans=0; 31 for (int i=1; i<=n; i++) //一看是这里没清,,,,iq--,,,暴力都不对。。。 32 for (int j=1; j<=n; j++) 33 f[i][j]=0; 34 for (int i=1; i<=n; i++) 35 for (int j=1; j<=n; j++) 36 if (!vis[i][j] && !f[i][j]) dfs(i,j); 37 return ans; 38 } 39 int main(int argc, char const *argv[]) 40 { 41 n=ra(); 42 for (int i=1; i<=n; i++) 43 for (int j=1; j<=n; j++) a[i][j]=ra(); 44 m=ra(); 45 while (m--) 46 { 47 char opt[2]; scanf("%s",opt+1); 48 if (opt[1]=='Q') printf("%d ",get_ans()); 49 if (opt[1]=='C') a[ra()][ra()]=ra(); 50 if (opt[1]=='S') 51 { 52 int x1=ra(),y1=ra(),x2=ra(),y2=ra(); 53 for (int i=x1; i<=x2; i++) 54 for (int j=y1; j<=y2; j++) 55 vis[i][j]=1; 56 } 57 if (opt[1]=='B') 58 { 59 int x1=ra(),y1=ra(),x2=ra(),y2=ra(); 60 for (int i=x1; i<=x2; i++) 61 for (int j=y1; j<=y2; j++) 62 vis[i][j]=0; 63 } 64 } 65 return 0; 66 }