zoukankan      html  css  js  c++  java
  • P1556 幸福的路

      emmm……

      为啥没一次AC呢?

      因为一堆if后面一个else,else对应的只是它上面那一个if。

      ……

      其余的暴力即可…

      还是把代码贴出来:

    #include<cstdio>
    #include<cstring>
    using namespace std;
    int n;
    struct xy
    {
        int x;
        int y;
        int b;
        int dir;
    } c[15];
    int ans;
    bool s;
    int last;
    int now;
    void dfs(int x,int y,int t)
    {
        if(t==0)
        {
            if(x==0||y==0)
            {
                if(x<0)
                    now=1;
                if(x>0)
                    now=3;
                if(y<0)
                    now=2;
                if(y>0)
                    now=4;
                if(now==last)
                    return ;
                ans++;
            }
            return ;
        }
        for(int i=1; i<=n; i++)
        {
            if(c[i].x==x||c[i].y==y)
            {
                if((c[i].x==x&&c[i].y==y)||c[i].b==1)
                    continue;
                else
                {
                    if(c[i].x>x)
                    {
                        c[i].dir=1;
                    }
                    if(c[i].x<x)
                    {
                        c[i].dir=3;
                    }
                    if(c[i].y>y)
                    {
                        c[i].dir=2;
                    }
                    if(c[i].y<y)
                    {
                        c[i].dir=4;
                    }
                    if(last==c[i].dir)
                        continue ;
                    int qwq=last;
                    last=c[i].dir;
                    //printf("**********%d %d %d
    ",c[i].x,c[i].y,c[i].dir);
                    c[i].b=1;
                    dfs(c[i].x,c[i].y,t-1);
                    last=qwq;
                    c[i].b=0;
                    c[i].dir=0;
                }
            }
        }
        return ;
    }
    int main()
    {
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d",&c[i].x,&c[i].y);
            c[i].b=0;
        }
        dfs(0,0,n);
        printf("%d",ans);
        return 0;
    }
  • 相关阅读:
    Lambda表达式
    多态的实现原理
    泛型
    tomcat
    nginx
    列举cocoa touch 常用框架
    写出你对MVC模式的理解
    写一个委托的interface
    写一个“标准”宏MIN 这个宏输入两个参数并返回较小的一个
    简介Object-C的内存管理
  • 原文地址:https://www.cnblogs.com/popo-black-cat/p/10028331.html
Copyright © 2011-2022 走看看