HGerdd @ 2024-03-05 21:04:46
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int flag = 0;
void chess(vector<vector<int>> &a,int x, int y,int m, int n,int size)
{
if(size == 1) return;
int t = flag++;
int s = size/2;
if(m < s+x && n < s+y)
{
chess(a,x,y,m,n,s);
}else
{
a[s+x-1][s+y-1] = t;
cout << s+x-1 << s+y-1 << t << endl;
chess(a,x,y,s+x-1,s+y-1,s);
}
if(m < s+x && n >= s+y)
{
chess(a,x,y+s,m,n,s);
}else
{
a[s+x-1][s+y] = t;
cout << s+x-1 << s+y << t << endl;
chess(a,x,y+s,s+x-1,s+y,s);
}
if(m >= s+x && n < s+y)
{
chess(a,x+s,y,m,n,s);
}else
{
a[s+x][s+y-1] = t;
cout << s+x << s+y-1 << t << endl;
chess(a,x+s,y,s+x,s+y-1,s);
}
if(m >= s+x && n >= s+y)
{
chess(a,x+s,y+s,m,n,s);
}else
{
a[s+x][s+y] = t;
cout << s+x << s+y << t << endl;
chess(a,x+s,y+s,s+x,s+y,s);
}
return;
}
int main()
{
vector<vector<int>> a(2000,vector<int>(2000));
int k,x,y;
cin >> k;
cin >> x >> y;
int s = 1;
for(int i = 1; i <= k; i++)
{
s *= 2;
}
chess(a,1,1,x,y,s);
return 0;
}
by HGerdd @ 2024-03-18 14:48:04
样例每过,但是检测都过了,有点怪
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int flag = 0;
void chess(vector<vector<int>> &a,int x, int y,int m, int n,int size)
{
if(size == 1) return;
//int t = flag++;
int s = size/2;
if(m < s+x && n < s+y)
{
cout << s+x << ' ' << s+y << ' ' << 1 << endl;
chess(a,x,y,m,n,s);
}else
{
//a[s+x-1][s+y-1] = t;
chess(a,x,y,s+x-1,s+y-1,s);
}
if(m < s+x && n >= s+y)
{
cout << s+x << ' ' << s+y-1 << ' ' << 2 << endl;
chess(a,x,y+s,m,n,s);
}else
{
//a[s+x-1][s+y] = t;
chess(a,x,y+s,s+x-1,s+y,s);
}
if(m >= s+x && n < s+y)
{
cout << s+x-1 << ' ' << s+y << ' ' << 3 << endl;
chess(a,x+s,y,m,n,s);
}else
{
//a[s+x][s+y-1] = t;
chess(a,x+s,y,s+x,s+y-1,s);
}
if(m >= s+x && n >= s+y)
{
cout << s+x-1 << ' ' << s+y-1 << ' ' << 4 << endl;
chess(a,x+s,y+s,m,n,s);
}else
{
//a[s+x][s+y] = t;
chess(a,x+s,y+s,s+x,s+y,s);
}
return;
}
int main()
{
vector<vector<int>> a(2000,vector<int>(2000));
int k,x,y;
cin >> k;
cin >> x >> y;
int s = 1;
for(int i = 1; i <= k; i++)
{
s *= 2;
}
chess(a,1,1,x,y,s);
return 0;
}
by fp0cy1tz6mn4rd_ @ 2024-03-24 15:02:11
@HGerdd 顺序不一样没关系
by fp0cy1tz6mn4rd_ @ 2024-03-24 15:02:24
@HGerdd 方案不一样也没关系
by remake1958 @ 2024-03-31 14:19:47
这不奇怪,按照分治的思想就是这样标记,在每个if里面标记拐角