zoukankan      html  css  js  c++  java
  • vijosP1016 北京2008的挂钟

    vijosP1016 北京2008的挂钟

    题目链接:https://vijos.org/p/1016

    【思路】

      Dfs。

      对操作搜索更加优秀,所以采用搜索每一个操作的使用次数,因为操作数为4则相当于没有操作,所以枚举上限为3。

    【代码】

     1 #include<iostream>
     2 #include<cstdlib>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 int op[9][9]={ {1,1,0,1,1,0,0,0,0},
     7                {1,1,1,0,0,0,0,0,0},
     8                {0,1,1,0,1,1,0,0,0},
     9                {1,0,0,1,0,0,1,0,0},
    10                {0,1,0,1,1,1,0,1,0},
    11                {0,0,1,0,0,1,0,0,1},
    12                {0,0,0,1,1,0,1,1,0},
    13                {0,0,0,0,0,0,1,1,1},
    14                {0,0,0,0,1,1,0,1,1}  };
    15 const int maxn = 10;
    16 int cnt[maxn],a[maxn],tmp[maxn];
    17 
    18 void dfs(int d) {
    19     memcpy(&tmp,&a,sizeof(a));
    20     
    21     for(int i=0;i<9;i++)
    22         for(int j=0;j<9;j++)
    23         {
    24            tmp[i]=(tmp[i]+op[j][i]*cnt[j])%4;
    25         }
    26     bool f=true;
    27     for(int i=0;i<9;i++) if(tmp[i]) {f=false; break; }
    28     if(f) {
    29         for(int i=0;i<9;i++)  //9
    30            for(int j=0;j<cnt[i];j++)
    31               cout<<i+1<<" ";
    32         exit(0);
    33     }
    34     if(d==9) return ;
    35     
    36     for(int i=0;i<4;i++) {
    37         cnt[d]=i;
    38         dfs(d+1);
    39     }
    40 }
    41 
    42 int main() {
    43     ios::sync_with_stdio(false);
    44     for(int i=0;i<9;i++) cin>>a[i];
    45     
    46     dfs(0);
    47     
    48     return 0;
    49 }
  • 相关阅读:
    Java中的逆变与协变
    JAVA中使用DOM解析XML文件
    ReentrantLock的使用
    tomcat源码 Container
    tomcat源码 Connector
    tomcat源码 StandardService
    BlockingQueue队列
    tomcat源码 StandardServer
    tomcat源码 分析 Catalina
    tomcat整体架构
  • 原文地址:https://www.cnblogs.com/lidaxin/p/4869864.html
Copyright © 2011-2022 走看看