zoukankan      html  css  js  c++  java
  • The 15th Zhejiang University Programming Contest B Valid Pattern Lock 构造

    题意:给你 3*3的手机解锁图,问你解锁线段只穿过指定的点的种类数。

    解题思路:把所有不能组成的组合打表出来特判 next_permutation就行了。

    解题代码:

     1 // File Name: b.cpp
     2 // Author: darkdream
     3 // Created Time: 2015年04月12日 星期日 13时51分52秒
     4 
     5 #include<vector>
     6 #include<list>
     7 #include<map>
     8 #include<set>
     9 #include<deque>
    10 #include<stack>
    11 #include<bitset>
    12 #include<algorithm>
    13 #include<functional>
    14 #include<numeric>
    15 #include<utility>
    16 #include<sstream>
    17 #include<iostream>
    18 #include<iomanip>
    19 #include<cstdio>
    20 #include<cmath>
    21 #include<cstdlib>
    22 #include<cstring>
    23 #include<ctime>
    24 #define LL long long
    25 
    26 using namespace std;
    27 int t; 
    28 int n;
    29 int a[15];
    30 int notok[][3] ={
    31     {1,3,2},{3,1,2},{1,7,4},{7,1,4},
    32     {1,9,5},{9,1,5},{4,6,5},{6,4,5},
    33     {7,9,8},{9,7,8},{7,3,5},{3,7,5},
    34     {2,8,5},{8,2,5},{3,9,6},{9,3,6}
    35 };
    36 int vis[15];
    37 int ok()
    38 {
    39     int visn[15];
    40     memset(visn,0,sizeof(visn));
    41     for(int j = 1;j <= n-1;j ++)
    42     {
    43         for(int i = 0 ;i <= 15;i ++)
    44         {
    45             if(a[j] == notok[i][0] && a[j+1] == notok[i][1] &&visn[notok[i][2]] == 0 )
    46                 return 0 ;
    47         }
    48         visn[a[j]] = 1;
    49     }
    50     return 1; 
    51 }
    52 int main(){
    53     scanf("%d",&t);
    54     while(t--)
    55     {
    56         scanf("%d",&n);
    57         memset(vis,0,sizeof(vis));
    58         for(int i = 1;i <= n;i ++)
    59         {
    60             scanf("%d",&a[i]);
    61             vis[a[i]] = 1; 
    62         }
    63         int ans = 0 ; 
    64         sort(a+1,a+1+n);
    65         do{
    66             if(ok())
    67                 ans ++ ; 
    68         }while(next_permutation(a+1,a+1+n));
    69         printf("%d
    ",ans);
    70         sort(a+1,a+1+n);
    71         int tt = 0 ; 
    72         do{
    73             if(ok())
    74             {
    75                 for(int i = 1;i <= n;i ++)
    76                     printf(i == 1?"%d":" %d",a[i]);
    77                 printf("
    ");
    78                 tt ++;
    79             }
    80         }while(next_permutation(a+1,a+1+n));
    81         //printf("%d
    ",tt);
    82         
    83     }
    84     return 0;
    85 }
    View Code
  • 相关阅读:
    Asp.NET 4.0 ajax实例DataView 模板编程1
    ASP.NET 4.0 Ajax 实例DataView模板编程 DEMO 下载
    部分东北话、北京话
    .NET 培训课程解析(一)
    ASP.NET 4.0 Ajax 实例DataView模板编程2
    ASP.NET Web Game 架构设计1服务器基本结构
    ASP.NET Web Game 构架设计2数据库设计
    TFS2008 基本安装
    Linux上Oracle 11g安装步骤图解
    plsql developer远程连接oracle数据库
  • 原文地址:https://www.cnblogs.com/zyue/p/4423130.html
Copyright © 2011-2022 走看看