uva-10098
所有的排列,但是要不重复
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include<time.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define N 12
int vis[N];
char a[N];
char b[N];
int length;
int n;
int final = 0;
void dfs(int cur)
{
if(cur == length)
{
for(int i = 0; i < cur; i++)
cout << b[i];
cout << endl;
return;
}
for(int i = 0; i < length; i++)
{
if(!i || a[i] != a[i - 1])
{
int c1 = 0, c2 = 0;
for(int j = 0; j < cur; j++)
if(b[j] == a[i])
c1++; for(int j = 0; j < length; j++)
if(a[j] == a[i])
c2++;
if(c1 < c2)
{
b[cur] = a[i];
dfs(cur + 1);
}
} }
}
void sort()
{
for(int i = 0; i < length; i++)
{
for(int j = 1; j < length - i; j++)
{
if(a[j] < a[j - 1])
{
char cc = a[j];
a[j] = a[j - 1];
a[j - 1] = cc;
}
}
} }
int main(const int argc, char** argv)
{
freopen("d:\\1.txt", "r", stdin);
cin >> n;
while (n--)
{
memset(a, 0, sizeof(a));
scanf("%s", a);
length = strlen(a);
sort();
dfs(0);
//if(n != 0)
cout << endl;
}
return 0;
}
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include<time.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define N 12
int vis[N];
char a[N];
char b[N];
int length;
int n;
int final = 0;
void dfs(int cur)
{
if(cur == length)
{
for(int i = 0; i < cur; i++)
cout << b[i];
cout << endl;
return;
}
for(int i = 0; i < length; i++)
{
if(!i || a[i] != a[i - 1])
{
int c1 = 0, c2 = 0;
for(int j = 0; j < cur; j++)
if(b[j] == a[i])
c1++; for(int j = 0; j < length; j++)
if(a[j] == a[i])
c2++;
if(c1 < c2)
{
b[cur] = a[i];
dfs(cur + 1);
}
} }
}
void sort()
{
for(int i = 0; i < length; i++)
{
for(int j = 1; j < length - i; j++)
{
if(a[j] < a[j - 1])
{
char cc = a[j];
a[j] = a[j - 1];
a[j - 1] = cc;
}
}
} }
int main(const int argc, char** argv)
{
freopen("d:\\1.txt", "r", stdin);
cin >> n;
while (n--)
{
memset(a, 0, sizeof(a));
scanf("%s", a);
length = strlen(a);
sort();
do
{
cout << a << endl;
} while (next_permutation(a, a + length));
cout << endl;
}
return 0;
}
想看库函数源码了。。。。。
uva-10098的更多相关文章
- UVA 10098 Generating Fast, Sorted Permutation
// 给你字符串 按字典序输出所有排列// 要是每个字母都不同 可以直接dfs ^_^// 用前面说的生成排列算法 也可以直接 stl next_permutation #include <io ...
- (组合数学3.1.1.2)UVA 10098 Generating Fast(使用字典序思想产生所有序列)
/* * UVA_10098.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> # ...
- UVa 10098: Generating Fast
这道题要求按字典序生成字符串的全排列,不可重复(但字符可以重复,且区分大小写). 基本思路是先对输入的字符串按字典序排序,然后从第一位开始递归,从所有输入的字符中选出一个填充,然后再选第二位..... ...
- UVA - 10098 - Generating Fast (枚举排列)
思路:生成全排列,用next_permutation.注意生成之前先对那个字符数组排序. AC代码: #include <cstdio> #include <cstring> ...
- uva 10098 Generating Fast(全排列)
还是用的两种方法,递归和STL,递归那个是含有反复元素的全排列,这道题我 没有尝试没有反复元素的排列,由于从题目上并没有发现一定是有反复元素的() 贴代码: <span style=" ...
- UVA 10098 用字典序思想生成所有排列组合
题目: Generating permutation has always been an important problem in computer science. In this problem ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
随机推荐
- Unity3D游戏-愤怒的小鸟游戏源码和教程(一)
Unity愤怒的小鸟游戏教程 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) AngryEva游戏效果: 1 ...
- HihoCoder - 1501:风格不统一如何写程序
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi写程序时习惯用蛇形命名法(snake case)为变量起名字,即用下划线将单词连接起来,例如:file_name. ...
- CTF-练习平台-Misc之 Linux??????
八.Linux?????? 下载文件,解压后只得到一个没有后缀名的文件,添加后缀名为txt,打开搜索,关键词为“flag”,没有找到:改关键词为“key”得到答案
- hdu2083 简易版之最短距离 排序水题
给出数轴n个坐标,求一个点到所有点距离总和最小.排序后最中间一个点或两个点之间就是最优 #include<stdio.h> #include<algorithm> using ...
- BitKeeper 和 Git
在 2002 年到 2005年, Linux 内核使用 BitKeeper 管理代码. BitKeeper 的 CEO 和 Linus 曾经是好友. 在 Git 诞生 11年后 BitKeeper 宣 ...
- 常见MQ流行度比较
MQ的流行度跟它的特性和应用场景密切相关,站在当下来看,kafka最火,rabbitmq用的也很多,ActiveMQ作为经典mq选择用它入门的也不少.
- 【转】linux下终端命令快捷键
原文网址:http://daaoao.blog.51cto.com/2329117/554177 linux下使用终端不可避免. 使用终端快捷键,当然会使你如虎添翼.记住他们吧 终端快捷键 tab=补 ...
- windows python3 安装gittle
1 从github clone gittle项目, git clone https://github.com/FriendCode/gittle.git 2 进行到下载的项目,执行安装 python ...
- php curl伪造来源ip和refer实例代码
php curl伪造来源ip和来路refer实例代码1: //随机IP function Rand_IP(){ $ip2id= round(rand(600000, 2550000) / 10000) ...
- Ubuntu 安装lrzsz工具
rz(上传) sz(下载)) 1. 安装 sudo apt-get install lrzsz 2. rz可覆盖原文件 rz -y