POJ - 1731 Orders

题意:排序后字符串全排列

思路:好久没水一题了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 220;

char str[MAXN];

int main() {
	while (scanf("%s", str) != EOF) {
		int n = strlen(str);
		sort(str, str+n);
		printf("%s\n", str);
		while (next_permutation(str, str+n))
			printf("%s\n", str);
	}
	return 0;
}

POJ - 1731 Orders,布布扣,bubuko.com

时间: 2024-10-18 11:44:58

POJ - 1731 Orders的相关文章

POJ 1731 Orders(带重复字母的全排列 + 暴力)

POJ 1731 Orders Description The stores manager has sorted all kinds of goods in an alphabetical order of their labels. All the kinds having labels starting with the same letter are stored in the same warehouse (i.e. in the same building) labelled wit

POJ 1731 Orders(STL运用)

题目地址:POJ 1731 这题能够直接用STL函数做,非常轻松..next_permutation函数非常给力.. 代码例如以下: #include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <queue> #include <cmath> #include <st

POJ 3187 Backward Digit Sums(next_permutation)

Description FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number. They repeat this until only a single number

整理——各种模板

便于考前用... 平时先囤着... hash                                                  ACM1996总决赛-10-20-30 extend euclid                                      poj 1061-青蛙的约会 拓扑排序                                              poj 1270-Following Orders dsu             

是时候学一波STL了。。。

都到如今了还不会STL,赶紧学习一下. .. 头文件#include<algorithm> 加上 using namespace std. 求下一个排列的函数:next_permutation(first,last),当中first,last都是指针变量.求的是区间 [first.last)的下一个排列.升序求得.比若说1 2 3 下一个排列是1 3 2.最后一个排列的下一个排列是第 一个.即3 2 1-->1 2 3.据说效率也不怎么样,poj 1833用G++交TLE.C++过了.

poj 1270 Following Orders(拓扑排序+dfs)

大致题意:每个样例包含两行,第一行输入n个字符,可能是无序的.第二行输入成对的a b,代表a要在b前面.输出所有的符合这样的序列. 思路:很明显的拓扑排序.要输出所有的序列,那么就从入度为0的点进行dfs,每次选择一个入度为0的点,加入输出序列并把与它相邻的点的入度减一.dfs结束后要把状态再改回来. #include <stdio.h> #include <algorithm> #include <set> #include <map> #include

POJ 1270 Following Orders

Following Orders Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4902   Accepted: 1982 Description Order is an important concept in mathematics and in computer science. For example, Zorn's Lemma states: ``a partially ordered set in which

UVA 124 &amp; POJ 1270 Following Orders(拓扑排序)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=60 http://poj.org/problem?id=1270 Following Orders Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3806   Accepted: 1507 Description Or

poj 1270 Following Orders 枚举排列

题意: 给一个字符集和一些字符之间的小于关系,求字符集上的所有可能排列. 分析: 暴力枚举可以分为枚举子集,枚举排列,枚举组合,这题是个简单的枚举排列,枚举过程中用小于关系剪枝即可. 代码: //poj 1270 //sep9 #include <iostream> #include <algorithm> using namespace std; char vars[64],constraint[256],ans[64]; int g[128][128],vis[256]; in