2020 Multi-University Training Contest 4---- HDU--6813、 Last Problem (构造)

题目链接

题面:
在这里插入图片描述

题意:
给定一张无限大的坐标平面,你可以在节点 ( 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值