DFS+模拟 ZOJ 3861 Valid Pattern Lock
/*
题意:手机划屏解锁,一笔连通所有数字,输出所有可能的路径;
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的更多相关文章
- ZOJ 3861 - Valid Pattern Lock
3861 - Valid Pattern Lock Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & ...
- ACM学习历程—ZOJ 3861 Valid Pattern Lock(dfs)
Description Pattern lock security is generally used in Android handsets instead of a password. The p ...
- 浙江大学2015年校赛B题 ZOJ 3861 Valid Pattern Lock
这道题目是队友写的,貌似是用暴力枚举出来. 题意:给出一组数,要求这组数在解锁的界面可能的滑动序列. 思路:按照是否能够直接到达建图,如1可以直接到2,但是1不能直接到3,因为中间必须经过一个2. 要 ...
- ZOJ - 3861 Valid Pattern Lock 【全排列】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3861 思路 先生成全排列,然后判断哪些情况不符合的,剔除就好了 ...
- ZOJ Problem Set - 3861 Valid Pattern Lock(dfs)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3861 这道题当时没做出来,后来经过队友提醒才做出来. 3*3的九宫格,给你 ...
- Valid Pattern Lock(dfs + 暴力)
Valid Pattern Lock Time Limit: 2 Seconds Memory Limit: 65536 KB Pattern lock security is genera ...
- zoj 3861(dfs)
Valid Pattern Lock Time Limit: 2 Seconds Memory Limit: 65536 KB Pattern lock security is genera ...
- 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 ...
- 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 ...
随机推荐
- 以Python角度学习Javascript(一)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO4AAADZCAIAAACo85tgAAAgAElEQVR4Aey9SdAs13XnV/P8jW8e8D ...
- Django authentication 使用方法
转自 : https://docs.djangoproject.com/en/1.8/topics/auth/customizing/
- 【Python】python代码如何调试?
Python 程序如何高效地调试? 现在我在debug python程序就只是简单在有可能错误的地方print出来看一下,不知道python有没像c++的一些IDE一样有单步调试这类的工具?或者说各位 ...
- 基础知识《六》---Java集合类: Set、List、Map、Queue使用场景梳理
本文转载自LittleHann 相关学习资料 http://files.cnblogs.com/LittleHann/java%E9%9B%86%E5%90%88%E6%8E%92%E5%BA%8F% ...
- hadoop(一):深度剖析hdfs原理
在配置hbase集群将 hdfs 挂接到其它镜像盘时,有不少困惑的地方,结合以前的资料再次学习; 大数据底层技术的三大基石起源于Google在2006年之前的三篇论文GFS.Map-Reduce. ...
- JSON: property "xxx" has no getter method in class "..."
Exception in thread "main" net.sf.json.JSONException: java.lang.NoSuchMethodException: Pro ...
- 在Android上使用fontAwesome
再也不用做那些讨厌的小图标了! 从网上找了些资料,总结下在android上使用fontAwesome的方法. 1.到官网上下载资源包,找到其中的字体文件fontawesome-webfont.ttf, ...
- codeforces B. Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/359/B 题目意思:给定n和k的值,需要构造一条长度为2n(每个元素取值范围只能是[1,2n])且元素各不 ...
- 处理html5离线应用程序存储的一些问题。
manifest方法引入appcache文件,缓存页面,是html5的新特性,通过加载一次,下次自动读取缓存,加载速度快,离线也能加载.缺点就是,被加载的页面会被强制缓存所有的内容. 为了解决不加载所 ...
- HTTP状态码整理
状态消息 1xx:信息 消息 描述 100 Continue 服务器仅接收到部分请求,但是一旦服务器并没有拒绝该请求,客户端应该继续发送其余的请求. 101 Switching Protocols 服 ...