题目传送门

 /*
题意:手机划屏解锁,一笔连通所有数字,输出所有可能的路径;
DFS:全排列 + ok () 判断函数,去除一些不可能连通的点:)
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
using namespace std; const int MAXN = ;
const int INF = 0x3f3f3f3f;
int a[], ans[];
int n, x;
int vis[];
int res[MAXN][];
int flag[]; bool ok(void)
{
memset (flag, , sizeof (flag)); int i;
for (i=; i<=n-; i++) //小细节决定成败
{
flag[ans[i]] = ;
if((ans[i] == && ans[i+] == && flag[] == )|| (ans[i] == && ans[i+] == && flag[] == ) ||
(ans[i] == && ans[i+] == && flag[] == )|| (ans[i] == && ans[i+] == && flag[] == ) ||
(ans[i] == && ans[i+] == && flag[] == )|| (ans[i] == && ans[i+] == && flag[] == ) ||
(ans[i] == && ans[i+] == && flag[] == )|| (ans[i] == && ans[i+] == && flag[] == ) ||
(ans[i] == && ans[i+] == && flag[] == )|| (ans[i] == && ans[i+] == && flag[] == ) ||
(ans[i] == && ans[i+] == && flag[] == )|| (ans[i] == && ans[i+] == && flag[] == ) ||
(ans[i] == && ans[i+] == && flag[] == )|| (ans[i] == && ans[i+] == && flag[] == ) ||
(ans[i] == && ans[i+] == && flag[] == )|| (ans[i] == && ans[i+] == && flag[] == ) )
return ; }
if(i == n)
return true;
} void DFS(int cnt)
{
if (cnt == n + )
{
if (ok ())
{
x++;
for (int i=; i<=n; i++)
{
res[x][i] = ans[i];
}
} return ;
} for (int i=; i<=n; i++)
{
if (!vis[a[i]])
{
ans[cnt] = a[i];
vis[a[i]] = ;
DFS (cnt + );
vis[a[i]] = ;
}
}
} int main(void) //ZOJ 3861 Valid Pattern Lock
{
//freopen ("B.in", "r", stdin); int t;
scanf ("%d", &t);
while (t--)
{
//memset (res, -1, sizeof (res)); //这句话没写导致WA n次!!!
memset (vis, , sizeof (vis)); //注意初始化,上面的作用已在ok () Debug 出来了
scanf ("%d", &n); for (int i=; i<=n; ++i) scanf ("%d", &a[i]);
sort(a+,a+n+);
x = ;
DFS (); printf ("%d\n", x);
for (int i=; i<=x; ++i)
{
for (int j=; j<=n; ++j)
{
printf ("%d%c", res[i][j], (j==n) ? '\n' : ' ');
}
} } return ;
}

DFS+模拟 ZOJ 3861 Valid Pattern Lock的更多相关文章

  1. ZOJ 3861 - Valid Pattern Lock

    3861 - Valid Pattern Lock Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & ...

  2. ACM学习历程—ZOJ 3861 Valid Pattern Lock(dfs)

    Description Pattern lock security is generally used in Android handsets instead of a password. The p ...

  3. 浙江大学2015年校赛B题 ZOJ 3861 Valid Pattern Lock

    这道题目是队友写的,貌似是用暴力枚举出来. 题意:给出一组数,要求这组数在解锁的界面可能的滑动序列. 思路:按照是否能够直接到达建图,如1可以直接到2,但是1不能直接到3,因为中间必须经过一个2. 要 ...

  4. ZOJ - 3861 Valid Pattern Lock 【全排列】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3861 思路 先生成全排列,然后判断哪些情况不符合的,剔除就好了 ...

  5. ZOJ Problem Set - 3861 Valid Pattern Lock(dfs)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3861 这道题当时没做出来,后来经过队友提醒才做出来. 3*3的九宫格,给你 ...

  6. Valid Pattern Lock(dfs + 暴力)

    Valid Pattern Lock Time Limit: 2 Seconds      Memory Limit: 65536 KB Pattern lock security is genera ...

  7. zoj 3861(dfs)

    Valid Pattern Lock Time Limit: 2 Seconds      Memory Limit: 65536 KB Pattern lock security is genera ...

  8. Bypass pattern lock on Sony Xperia Z2 and backup all data

    Yesterday she came to me with a Sony Xperia Z2 D6503. Guess what? She forgot the pattern so she coul ...

  9. Deal with Android phones with pattern lock on

    Yesterday my colleague asked me for help...She has two android phones , one is hTC and the other is ...

随机推荐

  1. 用WP_Query自定义WordPress 主循环

    我们知道操作 WordPress 主循环(WordPress Loop)最容易的方法是使用 query_posts 函数. 但是使用 query_posts 直接修改 WordPress 默认的主循环 ...

  2. Marriage Ceremonies(状态压缩dp)

     Marriage Ceremonies Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  3. 【转】使用genstring和NSLocalizedString实现App文本的本地化

    原地址:http://www.cnblogs.com/U-tansuo/p/IOS_NSLocalizedString.html iOS提供了简便的方法来实现本地化,其中用的最多的就是NSLocali ...

  4. Numeric Validation

    Numeric Inputs Numbers are even easier to validate than text. For number input types, the HTML5 spec ...

  5. C#结构体和类的区别

    1.不能在结构体中定义默认构造方法: 2.在结构体中的非默认构造方法中,必须对结构体中所有的字段进行初始化,否则将报错. 3.在类中声明字段的同时,可以初始化,字段的值.在结构体中不可以. 4.结构体 ...

  6. The content of element type "package" must match "(result-types?,interceptors?...

    错误:“The content of element type "package" must match "(result-types?,interceptors?,de ...

  7. onfiguration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]

    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Una ...

  8. win7 64位系统HP LaserJet P1008 / HP LaserJet P1008 P1007 驱动安装成功,但无法打印的原因

    HP LaserJet P1008 打印机驱动安装成功,但是无法打印相关文档的原因是: 1.打印机是水货,惠普中国提供的驱动和该打印机不符合.显示的应该是HP LaserJet Professiona ...

  9. 取出type="button" 和type="text" 里面的值显示在页面

    <script  type="text/JavaScript> function changeLink() { document.getElementById("nod ...

  10. 67. 总结篇:面试中随机数"等概率"vs"不等概率"生成问题[random generator with equal or unequal probability]

    [本文链接] http://www.cnblogs.com/hellogiser/p/random-generator-with-equal-or-unequal-probability.html 1 ...