zoukankan      html  css  js  c++  java
  • HDU 6813 Last Problem (构造+dfs)

    题意:有个无限大的画板,初始均为空,张三想画出数字n,如果他想画下数字n (n5)n (n≥5),需要保证四周的数字为n1, n2, n3, n4如果n≤4,只需要保证大于0的数字出现在四周即可,输出可以画出n的步骤。必然是有解的。n<100

    题解:n很小,且必然有解,可以考虑确定一个n的位置对其四周开始dfs,但是搜索的顺序不是无序必须保证n-1与n-4(n-2和n-3)分隔在n的两侧才能保证搜索之间不会相互覆盖。

    #include <bits/stdc++.h>
    #define IO_read ios::sync_with_stdio(false);cin.tie(0)
    #define fre freopen("C:\in.txt", "r", stdin)
    #define _for(i,a,b) for(int i=a; i< b; i++)
    #define _rep(i,a,b) for(int i=a; i<=b; i++)
    #define inf 0x3f3f3f3f
    #define lowbit(a) ((a)&-(a))
    using namespace std;
    typedef long long ll;
    template <class T>
    void read(T &x)
    {
        char c; bool op=0;
        while(c=getchar(), c<'0'||c>'9') if(c=='-') op=1;
        x=c-'0';
        while(c=getchar(), c>='0'&&c<='9') x=x*10+c-'0';
        if(op) x=-x;
    }
    template <class T>
    void write(T x)
    {
        if(x<0) putchar('-'), x=-x;
        if(x>=10) write(x/10);
        putchar('0'+x%10);
    }
    
    const int maxn=1e3+5;
    int n, pos[maxn][maxn];
    int dx[]={0, -1, 1, 0}, dy[]={-1, 0, 0, 1};
    
    void dfs(int x, int y, int val)
    {
        if(val<=0) return;
        _for(k, 0, 4){
            int nx=x+dx[k], ny=y+dy[k];
            if(pos[nx][ny]!=val-k-1)
                dfs(nx, ny, val-k-1);
        }
        pos[x][y]=val;
        printf("%d %d %d
    ", x, y, val);
    }
    
    
    int main()
    {
        freopen("out.txt", "w", stdout);
        clock_t st, ed;
        read(n);
        st=clock();
        dfs(500, 500, n);
        ed=clock();
        //printf("%f", (double)(ed-st)/CLOCKS_PER_SEC);
        return 0;
    }
  • 相关阅读:
    资料
    CSS 折角效果
    CSS3 动画
    选择器--验证表单
    -moz 火狐 -msIE -webkit[chrome safari]
    css3 fileter始终效果 图片渲染
    jquery 库下载地址http://www.jq22.com/jquery-info122
    CSS 文字垂直居中
    图片预加载技术(存在问题,已修复)
    Round#628(div2)
  • 原文地址:https://www.cnblogs.com/Yokel062/p/13417855.html
Copyright © 2011-2022 走看看