//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
#define F first
#define S second
int n,m,mk[105][105],cnt[105][105],wt[105][105];
int main(){
int odd,even,p,q,r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;
si(x1);
f(t,1,x1+1){
clr(mk,0);
clr(wt,0);
odd=0;even=0;
sii(n,m);
sii(l,r);
si(z);
f(i,0,z){
sii(x,y);
wt[x][y]=1;
}
vector<pii > v;
if(l!=0 && r!=0 && l!=r){
v.pb(mp(l,r));v.pb(mp(-l,r));v.pb(mp(l,-r));v.pb(mp(-l,-r));
v.pb(mp(r,l));v.pb(mp(-r,l));v.pb(mp(r,-l));v.pb(mp(-r,-l));
}
else if(l==0 && r!=0){
v.pb(mp(l,r));v.pb(mp(l,-r));
v.pb(mp(r,l));v.pb(mp(-r,l));
}
else if(r==0 && l!=0){
v.pb(mp(l,r));v.pb(mp(-l,r));
v.pb(mp(r,l));v.pb(mp(r,-l));
}
else if(l==r && l!=0){
v.pb(mp(l,r));v.pb(mp(-l,r));v.pb(mp(l,-r));v.pb(mp(-l,-r));
}
queue<pii > qq;
qq.push(mp(0,0));
mk[0][0]=1;
while(!qq.empty()){
pii pp=qq.front();
x=pp.F;y=pp.S;
qq.pop();
c=0;
f(i,0,v.size()){
p=x+v[i].F;q=y+v[i].S;
if(p>=0 && p<n && q>=0 && q<m && !wt[p][q]){
if(!mk[p][q]){
qq.push(mp(p,q));
mk[p][q]=1;
}
c++;
}
}
if(c&1)
odd++;
else
even++;
}
printf("Case %d: %d %d\n",t,even,odd);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
#define F first
#define S second
int n,m,mk[105][105],cnt[105][105],wt[105][105];
int main(){
int odd,even,p,q,r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;
si(x1);
f(t,1,x1+1){
clr(mk,0);
clr(wt,0);
odd=0;even=0;
sii(n,m);
sii(l,r);
si(z);
f(i,0,z){
sii(x,y);
wt[x][y]=1;
}
vector<pii > v;
if(l!=0 && r!=0 && l!=r){
v.pb(mp(l,r));v.pb(mp(-l,r));v.pb(mp(l,-r));v.pb(mp(-l,-r));
v.pb(mp(r,l));v.pb(mp(-r,l));v.pb(mp(r,-l));v.pb(mp(-r,-l));
}
else if(l==0 && r!=0){
v.pb(mp(l,r));v.pb(mp(l,-r));
v.pb(mp(r,l));v.pb(mp(-r,l));
}
else if(r==0 && l!=0){
v.pb(mp(l,r));v.pb(mp(-l,r));
v.pb(mp(r,l));v.pb(mp(r,-l));
}
else if(l==r && l!=0){
v.pb(mp(l,r));v.pb(mp(-l,r));v.pb(mp(l,-r));v.pb(mp(-l,-r));
}
queue<pii > qq;
qq.push(mp(0,0));
mk[0][0]=1;
while(!qq.empty()){
pii pp=qq.front();
x=pp.F;y=pp.S;
qq.pop();
c=0;
f(i,0,v.size()){
p=x+v[i].F;q=y+v[i].S;
if(p>=0 && p<n && q>=0 && q<m && !wt[p][q]){
if(!mk[p][q]){
qq.push(mp(p,q));
mk[p][q]=1;
}
c++;
}
}
if(c&1)
odd++;
else
even++;
}
printf("Case %d: %d %d\n",t,even,odd);
}
return 0;
}
No comments:
Post a Comment