题面
Problem Description
It's the night before Zhang3's birthday, and she's preparing for her birthday party in the classroom. She has brought a huge birthday cake and some powerful tomatoes, and has decorated almost every corner of the classroom. However, the blackboard is still empty. The last thing to do is to draw a beautiful pattern on it.
The blackboard is regarded as an infinite plane, each integer point (x,y) has an integer value as its color. At the very beginning, the color of every point is 0.
Zhang3 has n crayons, labeled 1,2,…,n. Painting with the ith crayon, you can replace the color of some chosen integer point (x,y) with color i. It is called a step, and she will draw the pattern step by step.
According to Zhang3's judgement of beautiful patterns, there's a restriction: Just before you paint (x,y) into some color i, the last four colors of i must appear among the adjacent points of (x,y). The last four colors of i means colors from (i−4) to (i−1), ignoring those non-positive ones. Two integer points are adjacent if their Euclid distance is exactly one. (Note that a point is not adjacent to itself.) If the condition above is not satisfied, the step is not allowed.
Zhang3 doesn't want to waste crayons, so the final pattern should contain at least one point with color n. Please help her find a way to draw such a beautiful pattern.
Input
The only line of the input contains an integer n(1≤n≤100), the number of crayons.
Output
Print the steps in chronological order, each in a separate line. Notice that you should not print the number of steps.
In the ith line, print three integers xi,yi,ci, separated by spaces, indicating the ith step is to paint (xi,yi) into color ci.
Your answer should satisfy |xi|,|yi|≤109,1≤ci≤n. The number of steps should not exceed 105. The output file should not be larger than 5MB.
It can be proved that there is always a solution. Any solution that meets all of the requirements will be accepted.
Sample Input
4
Sample Output
0 0 1
1 0 1
0 1 2
1 1 3
1 -1 2
1 0 4
思路
爆搜。从最大的数开始填,如果可以填我们就填,小于等于0就返回。
代码实现
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#define rep(i,f_start,f_end) for (int i=f_start;i<=f_end;++i)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define MT(x,i) memset(x,i,sizeof(x) )
#define rev(i,start,end) for (int i=0;i<end;i++)
#define inf 0x3f3f3f3f
#define mp(x,y) make_pair(x,y)
#define lowbit(x) (x&-x)
#define MOD 1000000007
#define exp 1e-8
#define N 1000005
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int ,int> PII;
ll gcd (ll a,ll b) {return b?gcd (b,a%b):a; }
const int maxn=1e5+10;
const int mod=1e9+7;
map <PII, int > ma;
int n;
void dfs (int x,int y,int n) {
if (n<=0) return ;
if (ma[mp(x,y+1)]!=n-1) dfs (x,y+1,n-1);
if (ma[mp(x+1,y)]!=n-2) dfs (x+1,y,n-2);
if (ma[mp(x,y-1)]!=n-4) dfs (x,y-1,n-4);
if (ma[mp(x-1,y)]!=n-3) dfs (x-1,y,n-3);
printf ("%d %d %d
",x,y,n);
ma[mp(x,y)]=n;
}
int main () {
cin>>n;
dfs (0,0,n);
return 0;
}