1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #include<bits/stdc++.h> const int mxn=2008; using namespace std; int n,m,k,q; int a[mxn][mxn]; pair<int,int> rid[mxn][mxn]; pair<int,int>id[mxn][mxn]; int usef[mxn][mxn]; int TT; inline int get(int x,int y,int xx,int yy){ if(xx>2*max(n,m)+7)xx=2*max(n,m)+7; if(yy>2*max(n,m)+7)yy=2*max(n,m)+7; if(x<1)x=1; if(y<1)y=1; return a[xx][yy]-a[xx][y-1]-a[x-1][yy]+a[x-1][y-1]; } inline void solve(){ memset(a,0,sizeof(a)); memset(usef,0,sizeof(usef)); int lst=max(n,m)+3; for(int i=1;i<=n+m-1;++i){ int y=1,x=i+1-y; int ee=lst; for(;x>=1 and y<=m;){ if(x<=n){ rid[x][y]={i,ee}; id[i][ee]={x,y}; usef[i][ee]=1; } --x; ++y; ee+=2; } --lst; } for(int i=1;i<=k;++i){ int x,y;cin>>x>>y; int tx=rid[x][y].first,ty=rid[x][y].second; ++a[tx][ty]; } for(int i=0;i<=max(n,m)*2+7;++i)for(int j=0;j<=max(n,m)*2+7;++j){ if(i)a[i][j]+=a[i-1][j]; if(j)a[i][j]+=a[i][j-1]; if(i and j)a[i][j]-=a[i-1][j-1]; } cout<<"Case "<<TT<<":\n"; for(int ee=0;ee<q;++ee){ int d;cin>>d; int ans=0;pair<int,int>pos;pos={1,1}; for(int i=0;i<=max(n,m)*2+8;++i)for(int j=0;j<=max(n,m)*2+8;++j){ if(!usef[i][j])continue; int t=get(i-d,j-d,i+d,j+d); if(t>ans)ans=t,pos=id[i][j]; else if(t==ans){ pair<int,int>tpos=id[i][j]; if(tpos.second<pos.second or (tpos.second==pos.second and tpos.first<pos.first))pos=tpos; } } cout<<ans<<" ("<<pos.first<<","<<pos.second<<")\n"; } } int main(){ ios_base::sync_with_stdio(false); while(cin>>n>>m>>k>>q){ if(!n)break; ++TT; solve(); } return 0; }
|