题意

要求给出一组 包含 1 - N 的数字的序列 要求这个序列 满足 题给的限制条件

比如 1 2 就是 1 一定要在 2 前面

思路

因为 数据规模较小 可以用 全排列 然后判断每个序列 是否满足要求,如果满足 就输出 BREAK

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 = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30; const int INF = 0x3f3f3f3f;
const int maxn = 5e4 + 5;
const int MOD = 1e9 + 7; int main()
{
int n, m;
while (scanf("%d%d", &n, &m) && (n || m))
{
vector <pii> vis;
int a, b;
for (int i = 0; i < m; i++)
{
scanf("%d%d", &a, &b);
vis.pb(pii(a, b));
}
vector <int> v;
for (int i = 1; i <= n; i++)
v.pb(i);
do
{
map <int, int> m;
for (int i = 0; i < n; i++)
m[v[i]] = i;
vector <pii>::iterator it;
for (it = vis.begin(); it != vis.end(); it++)
{
if (m[(*it).first] > m[(*it).second])
break;
}
if (it != vis.end())
continue;
for (int i = 0; i < n; i++)
{
if (i)
printf(" ");
printf("%d", v[i]);
}
printf("\n");
break;
} while (next_permutation(v.begin(), v.end()));
}
}

UVA - 10305 【全排列】的更多相关文章

  1. UVA.10305 Maximum Product (暴力)

    UVA.10305 Maximum Product (暴力) 题意分析 直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可. 代码总览 #include <iostream&g ...

  2. UVA.10305 Ordering Tasks (拓扑排序)

    UVA.10305 Ordering Tasks 题意分析 详解请移步 算法学习 拓扑排序(TopSort) 拓扑排序的裸题 基本方法是,indegree表示入度表,vector存后继节点.在tops ...

  3. Ordering Tasks UVA - 10305 图的拓扑排序

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  4. Uva 10305 给任务排序

    题目链接:https://uva.onlinejudge.org/external/103/10305.pdf 紫书P167 拓扑排序. dfs——从一个点出发,dfs 与之相连的所有点,把本身放入到 ...

  5. UVa 10305 Ordering Tasks (例题 6-15)

    传送门: https://uva.onlinejudge.org/external/103/10305.pdf 拓扑排序(topological sort)简单题 自己代码的思路来自: ==>  ...

  6. uva 10305 ordering tasks(超级烂题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABHIAAAHDCAYAAABI5T2bAAAgAElEQVR4nOydPY7svLW1awQGNABHCm

  7. Uva 10305 - Ordering Tasks 拓扑排序基础水题 队列和dfs实现

    今天刚学的拓扑排序,大概搞懂后发现这题是赤裸裸的水题. 于是按自己想法敲了一遍,用queue做的,也就是Kahn算法,复杂度o(V+E),调完交上去,WA了... 于是检查了一遍又交了一发,还是WA. ...

  8. UVa 10305 (拓扑排序) Ordering Tasks

    题意: 经典的拓扑排序.有n个任务,然后某些任务必须安排在某些任务前面完成,输出一种满足要求的序列. 分析: 拓扑排序用离散里面的话来说就是将偏序关系拓展为全序关系.我们将“小于”这种关系看做一条有向 ...

  9. UVA 10305 Ordering Tasks

    题意: 给出n和m,n代表总共有几个箱子.接下来m行,每行有a,b,表示b在a之后.输出一个合理的序列. 分析: 简单的拓扑排序: 代码: #include <iostream>#incl ...

随机推荐

  1. 在cmd窗口输入命令遇到You must run this command from a command prompt with administrator privilege怎么办?

    点开始菜单,找到Accessories(附件),找到Command Prompt窗口,点右键,选“run as administrator”(以管理员身份运行),之后再执行先前的命令就好了. 2017 ...

  2. Linux下自动备份MySQL数据库详细操作步骤(转载)

    环境说明操作系统:CentOSIP:192.168.150.214Oracle数据库版本:Oracle11gR2用户:root 密码:123456端口:3306数据库:ts_0.ts_1.ts_2.t ...

  3. Java排序算法(三):直接插入排序

    [基本思想] 关键:在前面已经排好序的序列中找到合适的插入位置 步骤: 1. 从第一个元素開始,该元素能够觉得已经排好序. 2. 取出下一个元素.在已经排好序的元素序列中从后往前扫描进行比較. 3. ...

  4. Intellij IDEA 的使用

    前言: 为什么我要选择intellij idea呢?原因有三 1.曾经公司的项目 在myeclipse10中不稳定 myeclipse说不定什么时候就崩溃卡死了  而intellij非常稳定 2.界面 ...

  5. mysql去掉空格换行符

    http://blog.csdn.net/gt219/article/details/52038382

  6. MFC中几个函数的使用

      1.GetDlgItem() CWnd* GetDlgItem ( int nID ) const;这个就足够了(在MFC中经常这么用),如果你是在win32API下面写的话,那么一般创建一个窗口 ...

  7. 一步一步实现视频播放器client(二)

    实现主体界面:                 222.png (64.46 KB, 下载次数: 0) 下载附件  保存到相冊 前天 21:02 上传 比較常见的一种布局.以下几个button.点击后 ...

  8. condarc文件

    channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/ - https://mirrors.tuna.tsingh ...

  9. caffe2--------ImportError: No module named past.builtins

    whale@sea:~/anaconda2/lib/python2.7/site-packages$ python Python 2.7.14 |Anaconda custom (64-bit)| ( ...

  10. Tomcat安装与IDEA中的配置

    下载Tomcat 先从http://tomcat.apache.org/上下载tomcat9,根据你的系统版本来下载. 本地安装 下载之后解压到你的软件安装目录中,这是我的例子: 然后设置环境变量,如 ...