New_hope @ 2023-07-13 20:03:06
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int mp[1050][1050];
void F(LL l,LL x1,LL y1,LL nx,LL ny){
if(l == 1){
return;
}
l = l >> 1;
if(nx-x1 < l){
if(ny-y1 < l){
cout << x1+l << " " << y1+l << " " << 1 << endl;
F(l,x1,y1,nx,ny);//自己
F(l,x1,y1+l,x1+l-1,y1+l);//右上
F(l,x1+l,y1,x1+l,y1+l-1);//左下
F(l,x1+l,y1+l,y1+l,y1+l);//右下
}//左上
else{
cout << x1+l << " " << y1+(l>>1)-1 << " " << 2 << endl;
F(l,x1,y1,x1+l-1,y1+l-1);//左上
F(l,x1,y1+l,nx,ny); //自己
F(l,x1+l,y1,x1+l,y1+l-1);//左下
F(l,x1+l,y1+l,y1+l,y1+l);//右下
}//右上
}
else{
if(ny-y1 < l){
cout << x1+l-1 << " " << y1+l << " " << 3 << endl;
F(l,x1,y1,x1+l-1,y1+l-1); //左上
F(l,x1,y1+l,x1+l-1,y1+l);//右上
F(l,x1+l,y1,nx,ny);//自己
F(l,x1+l,y1+l,y1+l,y1+l);//右下
}//左下
else{
cout << x1+l-1 << " " << y1+l-1 << " " << 4 << endl;
F(l,x1,y1,x1+l-1,y1+l-1); //左上
F(l,x1,y1+l,x1+l-1,y1+l);//右上
F(l,x1+l,y1,x1+l,y1+l-1);//左下
F(l,x1+l,y1+l,nx,ny); //自己
}//右下
}
}
int main(){
LL x,y,k,l;
cin >> k >> x >> y;
l=1<<k;
F(l,1,1,x,y); //l->px,py;(i,j),(x,y)->一个正方形左上右下横纵坐标范围;nx,ny->特殊点位置
return 0;
}
//F(k,x1,y1,(x1+(1<<k))-1,(y1+(1<<k))-1,(x1+(1<<k))-1,(y1+(1<<k))-1);//左上
//F(k,x1,y1+1<<k,(x1+(1<<k))-1,y2,(x1+(1<<k))-1,y1+(1<<k));//右上
//F(k,x1+(1<<k),y1,x2,(y1+(1<<k))-1,x1+(1<<k),(y1+(1<<k))-1);//左下
//F(k,x1+(1<<k),y1+(1<<k),x2,y2,x1+(1<<k),y1+(1<<k));//右下
by Sytrus @ 2023-07-14 11:48:14
可以尝试用以下程序自查,输入实际边长(那个2的整数次幂),然后逐步输入自己代码运行结果每步的
#include<bits/stdc++.h>
using namespace std;
int k[1025][1025];
int main(){
int n;
cin>>n;
while(true){
int a,b,c;
cin>>a>>b>>c;
if(a==0) break;
k[a][b]++;
if(c==1){
k[a-1][b]++;
k[a][b-1]++;
}
else if(c==2){
k[a-1][b]++;
k[a][b+1]++;
}
else if(c==3){
k[a][b-1]++;
k[a+1][b]++;
}
else{
k[a][b+1]++;
k[a+1][b]++;
}
system("cls");
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<k[i][j]<<" ";
}
cout<<endl;
}
}
}
by New_hope @ 2023-07-24 21:06:16
@Lijb 好的