题目链接

题面:

题意:
给定一张无限大的坐标平面,你可以在节点 ( x , y ) (x,y) (x,y) 处填写数字,填写数字需要遵守一定的规则,输出在 1 e 5 1e5 1e5 步之内可以让数字 n n n 出现的一个构造方法。

规则:
如果当前要填写一个数字 x x x ,对于 1 i 4 1\le i \le4 1i4 x i x-i xi 要么非正,要么 x x x 上下左右四个点中的某个点为 x i x-i xi

题解:

即我们让 x 1 x-1 x1 出现在 x x x 的上方, x 2 x-2 x2 出现在 x x x 的左方, x 3 x-3 x3 出现在 x x x 的右方, x 4 x-4 x4 出现在 x x x 的下方,即可符合要求。

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<bitset>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<ctime>
#define ui unsigned int
#define ll long long
#define llu unsigned ll
#define ld long double
#define pr make_pair
#define pb push_back
//#define lc (cnt<<1)
//#define rc (cnt<<1|1)
#define len(x) (t[(x)].r-t[(x)].l+1)
#define tmid ((l+r)>>1)
#define fhead(x) for(int i=head[(x)];i;i=nt[i])
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
using namespace std;

const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
const double dnf=1e18;
const double alpha=0.75;
const int mod=1e9+7;
const double eps=1e-8;
const double pi=acos(-1.0);
const int hp=13331;
const int maxn=2100;
const int maxm=100100;
const int maxp=100100;
const int up=1100;

int ha[maxn][maxn];

void dfs(int x,int y,int n)
{
    if(n<=0) return ;
    if(ha[x][y]==n) return ;
    dfs(x-1,y,n-1);
    dfs(x,y-1,n-2);
    dfs(x,y+1,n-3);
    dfs(x+1,y,n-4);
    ha[x][y]=n;
    printf("%d %d %d\n",x,y,n);
}

int main(void)
{
    int n;
    scanf("%d",&n);
    dfs(1000,1000,n);
    return 0;
}