zoukankan      html  css  js  c++  java
  • 2020杭电多校联合训练(第四场) L.Last Problem (dfs)

    题面

    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;
    }
    
  • 相关阅读:
    CentOS ping: unknown host 解决方法
    chmod 777 修改权限
    Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器[摘抄]
    PHP-CGI 进程 CPU 100% 与 file_get_contents 函数的关系
    unix:/tmp/php-cgi.sock
    Nginx虚拟主机配置教程
    nginx 浏览php的时候会变成下载
    sphinx的配置和管理.No2
    Sphinx以及coreseek的安装及使用 .No1
    76、android:supportsRtl 和 android:layout_marginEnd
  • 原文地址:https://www.cnblogs.com/hhlya/p/13409905.html
Copyright © 2011-2022 走看看