ZOJ - 3861 Valid Pattern Lock 【全排列】
题目链接
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3861
思路
先生成全排列,然后判断哪些情况不符合的,剔除就好了
代码中 init() 部分 就是 先指明 哪两个数字之间 是必须有另外一个数字的
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
const double PI = acos(-1);
const double E = exp(1);
const double eps = 1e-30;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int MOD = 1e9 + 7;
int n;
int c[10][10];
int vis[10];
bool judge(vector <int> ans)
{
for (int i = 0; i < n - 1; i++)
{
if (c[ans[i]][ans[i + 1]] && vis[c[ans[i]][ans[i + 1]]] == 0)
return false;
vis[ans[i]] = 1;
}
return true;
}
void init()
{
CLR(c);
c[1][3] = 2, c[3][1] = 2;
c[1][7] = 4, c[7][1] = 4;
c[1][9] = 5, c[9][1] = 5;
c[2][8] = 5, c[8][2] = 5;
c[3][9] = 6, c[9][3] = 6;
c[3][7] = 5, c[7][3] = 5;
c[4][6] = 5, c[6][4] = 5;
c[7][9] = 8, c[9][7] = 8;
}
int main()
{
init();
int t;
cin >> t;
while (t--)
{
scanf("%d", &n);
vector <int> pre;
int num;
for (int i = 0; i < n; i++)
{
scanf("%d", &num);
pre.pb(num);
}
sort(pre.begin(), pre.end());
vector < vector <int> > ans;
do
{
CLR(vis);
if (judge(pre))
ans.pb(pre);
} while (next_permutation(pre.begin(), pre.end()));
int len = ans.size();
printf("%d\n", len);
for (int i = 0; i < len; i++)
{
for (int j = 0; j < n; j++)
{
if (j)
printf(" ");
printf("%d", ans[i][j]);
}
printf("\n");
}
}
}
ZOJ - 3861 Valid Pattern Lock 【全排列】的更多相关文章
- DFS+模拟 ZOJ 3861 Valid Pattern Lock
题目传送门 /* 题意:手机划屏解锁,一笔连通所有数字,输出所有可能的路径: DFS:全排列 + ok () 判断函数,去除一些不可能连通的点:) */ #include <cstdio> ...
- 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 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 ...
随机推荐
- 缠中说禅股票交易系统图解 z
缠中说禅股票交易系统图解 2010-03-23 10:51 (王纯阳)缠论祖师的经典语录 1. 就在买点买,卖点卖:当然,买点并不一定是一个点,一个价位,级别越大的,可以容忍的区间越大. 2. 你要经 ...
- 说说GestureDetector.OnGestureListener onScroll函数
public abstract boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) ...
- 区间最小值(2) (线段树 更新区间)2015年 JXNU_ACS 算法组暑假第一次周赛
区间最小值(2) Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Subm ...
- StringUtils和IOUtils工具包的使用
加载apache的工具类 <dependency> <groupId>commons-lang</groupId> <artifactId>common ...
- 先行发生原则(Happens-before)
先行发生原则(Happens-Before)是判断数据是否存在竞争.线程是否安全的主要依据. 先行发生是Java内存,模型中定义的两项操作之间的偏序关系,如果操作A先行发生于操作B,那么操作A产生的影 ...
- 微信小程序 - 对象转换成对象数组
后端传过来的一个个对象 {1,2,3,4},{1,3,5,},{1,3,5} 我们应该转化为数组对象 [{},{},{},{}] ,最后通过wx:for遍历到页面 示例图:
- 【Python】分析文本split()
分析单个文本 split()方法,是以空格为分隔符将字符串拆分成多个部分,并将这些部分存储到一个列表中 title = 'My name is oliver!' list = title.split( ...
- CSS环绕球体的旋转文字-3D效果
代码地址如下:http://www.demodashi.com/demo/12482.html 项目文件结构截图 只需要一个html文件既可: 项目截图: 代码实现原理: 该示例的实现过程很简单,主要 ...
- Koa2 + Mongoose + Log4js 持久化日志
代码地址如下:http://www.demodashi.com/demo/12466.html 之前做的项目是采用 Express 框架进行搭建的,其中的日志管理采用了 winston + Post ...
- Android网络编程Socket【实例解析】
Socket 事实上和JavaWeb 里面的Socket一模一样 建立客服端,server端,server开一个port供客服端訪问 第一步创建server端:(这里把为了便于解说.把server端, ...