标签:can for getc turn iostream using div sed tchar
留坑待填
T2
1 #include<cstdio> 2 #include<vector> 3 #include<cstring> 4 #include<iostream> 5 #include<algorithm> 6 #define R register 7 using namespace std; 8 inline int read() 9 { 10 int f=1,x=0;char ch=getchar(); 11 while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)f=-1;ch=getchar();} 12 while(ch<=‘9‘&&ch>=‘0‘){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();} 13 return f*x; 14 } 15 const int maxn=2005; 16 int n,m,q; 17 char a[2005][2005]; 18 int s[2005][2005],b[2005][2005],rb[2005][2005],cb[2005][2005];//s[i][j],b[i][j]从(i,j)到左上角的点数,边数,rb[i][j]第i行到j列的前缀和 19 int main() 20 { 21 //freopen("data","r",stdin); 22 n=read(),m=read(),q=read(); 23 for(R int i=1;i<=n;++i) 24 scanf("%s",a[i]+1); 25 for(int i=1;i<=n;++i) 26 { 27 int nws=0,nwb=0; 28 for(int j=1;j<=m;++j) 29 { 30 cb[i][j]=cb[i-1][j]; 31 rb[i][j]=rb[i][j-1]; 32 if(a[i][j]==‘1‘){ 33 nws++; 34 if(a[i-1][j]==‘1‘){nwb++;cb[i][j]++;} 35 if(a[i][j-1]==‘1‘){nwb++;rb[i][j]++;} 36 } 37 s[i][j]=s[i-1][j]+nws; 38 b[i][j]=b[i-1][j]+nwb; 39 } 40 } 41 for(R int i=1;i<=q;++i) 42 { 43 R int x=read(),y=read(),xx=read(),yy=read(); 44 int as=s[xx][yy]-s[x-1][yy]-(s[xx][y-1]-s[x-1][y-1]); 45 int ab=b[xx][yy]-b[x][yy]-(b[xx][y]-b[x][y])+(rb[x][yy]-rb[x][y])+(cb[xx][y]-cb[x][y]); 46 printf("%d\n",as-ab); 47 } 48 }
标签:can for getc turn iostream using div sed tchar
原文地址:https://www.cnblogs.com/casun547/p/11352486.html