题解 AT3967 【[AGC025D] Choosing Points】
Solution
首先只考虑一个
由于一定能黑白染色,所以就证明了得到的图一定是二分图。
那么问题变为有两张
时间复杂度
Code
int n,D1,D2;
int col[3][MAXN][MAXN],cnt[2][2];
void Solve(int d,int id){
int k = 0;
while(d % 4 == 0) d /= 4, k += 1;
if(d % 4 == 3) return;
k = 1 << k;
if(d % 4 == 1){
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++)
col[id][i][j] = ((i - 1) / k + (j - 1) / k) & 1;
}
}else{
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++)
col[id][i][j] = ((i - 1) / k) & 1;
}
}
}
int main(){
scanf("%d%d%d",&n,&D1,&D2);
n <<= 1;
Solve(D1,1);
Solve(D2,2);
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++)
cnt[col[1][i][j]][col[2][i][j]] += 1;
}
int x,y;
for(int i = 0;i < 2;i++){
for(int j = 0;j < 2;j++){
if(cnt[i][j] >= n * n / 4)
x = i, y = j;
}
}
int tot = 0;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
if(col[1][i][j] == x && col[2][i][j] == y){
printf("%d %d\n",i - 1,j - 1);
tot += 1;
if(tot >= n * n / 4) return 0;
}
}
}
return 0;
}