题目传送门

 /*
题意:手机划屏解锁,一笔连通所有数字,输出所有可能的路径;
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. dedecms如何随机调用指定分类下的文章到网站首页

    dedecms是全静态的,有时会因为其他事情好几天没写文章推荐到首页,那样对se不是很友好.原本ytkah是想在网站首页上半部分调用几篇id从200到500的文章随机展示的,这样每次更新首页给se的赶 ...

  2. The Pilots Brothers' refrigerator(dfs)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19718 ...

  3. IOS 使用横屏

    http://lizhuang.iteye.com/blog/1684881 在iPad应用开发时如何让设备只支持横屏(landscape)模式,我做了多次尝试,并没有发现比较简捷的设置方法.我尝试了 ...

  4. Hibernate执行原生SQL返回List<Map>类型结果集

    我是学java出身的,web是我主要一块: 在做项目的时候最让人别扭的就是hibernate查询大都是查询出List<T>(T指代对应实体类)类型 如果这时候我用的联合查询,那么返回都就是 ...

  5. Linux rpm安装问题解决

    1.安装时提示:warning: *.rpm: Header V3 RSA/SHA256 Signature, keykey ID c105b9de: NOKEY 解决的方法就是在rpm 语句后面加上 ...

  6. ubuntu14.04安装chrome

    到https://www.google.com/chrome/browser/desktop/index.html可下载指定版本的deb文件. 32bit: wget https://dl.googl ...

  7. 【Django】Django 直接执行原始SQL 如何防止SQL注入 ?

    代码示例: #错误--不要直接格式化字符串 query = 'SELECT * FROM myapp_person WHERE last_name = %s' % lname Person.objec ...

  8. 【leetcode】String to Integer (atoi)

    String to Integer (atoi) Implement atoi to convert a string to an integer. Hint: Carefully consider ...

  9. Java for LeetCode 187 Repeated DNA Sequences

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  10. 10.python之socket和socketserver

    1.socket介绍 socket的英文原义是"孔"或"插座".作为BSD UNIX的进程通信机制,取后一种意思.通常也 称作"套接字",用 ...