模拟20 题解(waiting)

Posted casun547

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了模拟20 题解(waiting)相关的知识,希望对你有一定的参考价值。

留坑待填

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 
View Code

 

以上是关于模拟20 题解(waiting)的主要内容,如果未能解决你的问题,请参考以下文章

PAT甲题题解-1014. Waiting in Line (30)-模拟,优先级队列

PAT (Advanced Level) 1014 Waiting in Line

PAT 1014 Waiting in Line (模拟)

1014. Waiting in Line (30)(模拟题)

1014 Waiting in Line (30 分) 未完成难度: 难 / 知识点: 大模拟

android waiting for debugger