#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<pair<int,int>,int> mp;
int t,n,k;
int check(int x,int y){
if((x==0&&(y==0||y==n-1))||(x==n-1&&(y==0||y==n-1)))return 3;
else if(x==0||x==n-1||y==0||y==n-1) return 4;
else return 5;
}
int dr1[4]={1,-1,0,0},dr2[4]={0,0,1,-1};
int main(){
scanf("%d",&t);
int cas=0;
while(t--){
scanf("%d%d",&n,&k);
if(n==1){
if(k==1) printf("0\n");
else printf("1\n");
break;
}
mp.clear();
for(int i=1;i<=k;i++){
int a,b;scanf("%d%d",&a,&b);
mp[{a,b}]=1;
}
ll sum=(n-2)*(n-2)*5+(n-2)*4*4+3*4;
ll sum2=(n-2)*2*4+3*3+(n-2)*(n-1)/2*5;
for(auto tp:mp){
pair<int,int> temp=tp.first;
int x=temp.first,y=temp.second;
if(x+y>=n-1) sum2-=check(x,y);
sum-=check(x,y);
for(int i=0;i<4;i++){
int tx=x+dr1[i],ty=y+dr2[i];
if(tx<0||tx>n-1||ty<0||ty>n-1) continue;
if(mp.count({tx,ty})==0){
sum-=(ll)1;
if(tx+ty>=n-1) sum2-=(ll)1;
}
// sum-=1;
}
}
ll gg=__gcd(sum,sum2);
// cout<<sum<<" "<<sum2<<endl;
// cout<<gg<<endl;
sum=sum/gg;
sum2=sum2/gg;
printf("Case #%d: %lld/%lld\n",++cas,sum2,sum);
}
}
Wandering Robots(规律
最新推荐文章于 2022-03-14 18:13:28 发布