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 ...
随机推荐
- xcode Git
http://blog.csdn.net/w13770269691/article/details/38704941 在已有的git库中搭建新库,并且将本地的git仓库,上传到远程服务器的git库中, ...
- MYSQL随机抽取查询 MySQL Order By Rand()效率问题
MYSQL随机抽取查询:MySQL Order By Rand()效率问题一直是开发人员的常见问题,俺们不是DBA,没有那么牛B,所只能慢慢研究咯,最近由于项目问题,需要大概研究了一下MYSQL的随机 ...
- jquery博客收集的IE6中CSS常见BUG全集及解决方案
今天的样式调的纠结,一会这边一会那么把jquery博客折腾的头大,浏览器兼容性.晚上闲着收集一些常见IE6中的BUG 3像素问题及解决办法 当使用float浮动容器后,在IE6下会产生3px的空隙,有 ...
- PHP 遍历目录
$dir = $_SERVER['DOCUMENT_ROOT'].'/test'; //var_dump($dir);exit; function my_scandir($dir) { $files ...
- java 实现二分查找法
/** * 二分查找又称折半查找,它是一种效率较高的查找方法. [二分查找要求]:1.必须采用顺序存储结构 2.必须按关键字大小有序排列. * @author Administrator * */ p ...
- MYSQL索引失效的各种情形总结
1) 没有查询条件,或者查询条件没有建立索引 2) 在查询条件上没有使用引导列 3) 查询的数量是大表的大部分,应该是30%以上. 4) 索引本身失效 5) 查询条件使用函数在索引列上,或者对索 ...
- 《ASP.NET MVC4 WEB编程》学习笔记------Web API
本文截取自情缘 1. Web API简单说明 近来很多大型的平台都公开了Web API.比如百度地图 Web API,做过地图相关的人都熟悉.公开服务这种方式可以使它易于与各种各样的设备和客户端平台集 ...
- iOS7 中的statusbar的隐藏和样式更改
ios7以前,如果想要隐藏statusbar,需要用到[UIApplicationsharedApplication].statusBarHidden = YES; 或者在plist文件中设定Stat ...
- Greedy:Radar Installation(POJ 1328)
装雷达 题目大意,就是令在海岸线的(直线)一边是海(y>0),另一边是陆地(y<=0),在海岸线上装雷达,雷达可以覆盖的范围为d,海上有岛,(x,y),问你应该怎么装雷达,才能做到技能雷达 ...
- HDU1286新朋友欧拉函数版
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...