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 ...
随机推荐
- Django 创建APP - 简单路由系统案例
架构图: setting.py: INSTALLED_APPS = [ ... 'bootstrap', ] myapp -> myapp -> urls.py from django.c ...
- android mvp高速开发框架介绍(继续dileber)
android mvp框架:dileber(https://github.com/dileber/dileber.git) 继续为大家介绍android mvp开源框架 dileber 官方交流qq群 ...
- IP反查网站,ip反查接口,旁站查询接口大全,通过IP查域名汇总:
http://cn.bing.com/search?q=ip%3A220.181.111.85 http://dns.aizhan.com/?q=www.baidu.com http: ...
- hadoop 使用和javaAPI
hadoop的安装,见http://www.powerxing.com/install-hadoop/,简略版教程见http://www.powerxing.com/install-hadoop-si ...
- vue2.0 仿手机新闻站(四)axios
1.axios的配置 main.js import Vue from 'vue' import App from './App.vue' // 引入 路由 import VueRouter from ...
- Vue避免 v-if 和 v-for 用在一起
永远不要把 v-if 和 v-for 同时用在同一个元素上. 一般我们在两种常见的情况下会倾向于这样做: 为了过滤一个列表中的项目 (比如 v-for="user in users" ...
- OCP学习基本知识点总结
下面是我总结的OCP教程的知识点.以备參考之用. 1, What's Oracle Server? · It's a database management system that ...
- IE67实现inline-block布局
inline-block可以定义元素为行内块级元素,即既具有行内元素同占一行的特点,又具有块级元素的box模型.但是IE67和其他浏览器的支持差别比较大: 1.行内元素使用inline-block变成 ...
- jquery列表自动加载更多
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 扩展MongoDB C# Driver的QueryBuilder
扩展MongoDB C# Driver的QueryBuilder 因为不想直接hardcode "ClassA.MemberA.MemberB" 这种字符串 .写了下面几个类,用于 ...