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谁大的问 ...
随机推荐
- Arpa’s obvious problem and Mehrdad’s terrible solution 思维
There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious ...
- ACM中的取模
取模本身的性质:(之前有一篇博客写过)三则运算(+,-,*)过程中的取模与最后的取模一样(前提是最后不超long long(或int) 范围,所以为防止超范围,直接对三则运算中的过程取模) 然后就是A ...
- vue components
https://github.com/vuejs/awesome-vue#components--libraries
- log4net保存到数据库系列一:WebConfig中配置log4net
园子里面有很多关于log4net保存到数据库的帖子,但是要动手操作还是比较不易,从头开始学习log4net数据库日志 一.WebConfig中配置log4net 二.独立配置文件中配置log4net ...
- 先进驾驶员辅助系统ADSA
ADSA(Advanced Driver-Assistance Systems)字面翻译过来是“先进驾驶员辅助系统”,实际上它是一种“辅助驾驶员更便捷更安全使用汽车”的系统. ADAS的研发历史可以追 ...
- 【python】python中__name__的使用
Py1.py #!/usr/bin/env python def test(): print '__name__ = ',__name__ if __name__ == '__main__': tes ...
- [转]Nginx负载均衡原理初解
什么是负载均衡 我们知道单台服务器的性能是有上限的,当流量很大时,就需要使用多台服务器来共同提供服务,这就是所谓的集群. 负载均衡服务器,就是用来把经过它的流量,按照某种方法,分配到集群中的各台服务器 ...
- ASP.NET 实现伪静态网页方法
方法一:利用Httphandler实现URL重写(伪URL及伪静态) 我们有时候会见到这样的地址:“http://www.huoho.com/show-12-34.html”,你或许认为在站点服务器根 ...
- WCF揭秘学习笔记(4):可信赖会话、会话管理、队列、事务
可信赖会话 WCF的可信赖会话在绑定层保证消息只会被传输一次,并且保证消息间的顺序.当使用TCP通信时,协议本身保证了可靠性,但它只在两点间的网络 包这个层面提供了这样的保证.WCF的可信赖会话特性保 ...
- 微信小程序的视频教程
极客学院小程序视频教程: 链接:https://pan.baidu.com/s/1VpKnvnsn-T6Nd79bsi4ugg 密码:0ta9 小程序项目实战: 链接:https://pan.baid ...