解题思路: 对于全排列的问题,STL,提供了一个强大的函数,
bool next_permutation(iterator.begin() , iterator.end());
对于当前的序列如果不是最后一个序列则返回真,否则返回假。
uva 10098 - Generating Fast
代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;
string str;
int main(){
int n;
scanf("%d" , &n);
while(n--){
string str;
cin>>str;
while(next_permutation(str.begin() , str.end())){
cout<<str<<endl;
}
cout<<endl;
}
return 0 ;
}
uva 729 - The Hamming Distance Problem
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main() {
int Case , n, h;
bool first = true;
scanf("%d" , &Case);
while(Case--){
if(first)
first = false;
else
printf("\n");
string str;
scanf("%d%d", &n, &h);
for (int i = 0; i < n; i++) {
if (i >= n - h)
str += '1';
else
str += '0';
}
cout<<str<<endl;
while (next_permutation(str.begin(), str.end()))
cout << str << endl;
}
return 0;
}
uva 146 - ID Codes
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
string str;
int main(){
while(cin>>str){
if(str == "#")
break;
if(next_permutation(str.begin(),str.end()))
cout<<str<<endl;
else
printf("No Successor\n");
}
return 0;
}
分享到:
相关推荐
uva11859nim游戏 + 求素因子个数.cpp
《算法竞赛入门经典》UVa配套题目pdf版完整
UVa在我看来是比较全的一个题解,希望能帮助大家。欢迎下载。
世界著名大学UVA OJ平台上的题目部分分类,分的不好请原谅。
这是uva250题目的算法的c源程序代码
这部分是提供给读者部分思路的题目代码,比较有代表性。
主要是uvaoj习题相关题目 练习题目
利用C#语言完成UVA题目回文词,使用前注意修改命名空间
这里面全部为在Uva Online Judge上面的部分题目的解答,里面提供了解答使用的源代码。
UVa写入 使用C ++编写UVa OJ: : 等级 基于 ★★ ★★ ★★★ ★★★★ ★★★★★ 未排名
Uva 100 ,问题是The 3n+1 probelm ,可以ac的代码
自己整理的UVa所有题目的PDF题面,可根据目录中的Volume快速跳转(与UVa官网一致)。 题目共4965题,PDF共8380页,可能会出现打开较慢的问题。 关于某个题目所在位置的判断方法: 题号除了后两位的其他数字构成...
算法竞赛入门经典(第二版)的习题都是UVa上的, 但是UVa太慢了太慢了太慢了太慢了太慢了, 于是我把各章习题的pdf一次性打包下载到本地, 和大家分享:)
UVA 题目,不是很难,试试吧
uva272
UVA109的题解,经测试完全正确,还附有题解。
分享这个文件的原因是国内上UVa太慢了,有时候UVa还会挂。 而且书里把输入输出样例省去了,这里整理出原题做个参考。 所以我把书里3-12章的每道例题和习题的UVa原题pdf下载整理。 上次上传的那个没有例题只有习题,...
有uva刘汝佳文件夹的50道题解,从数据结构开始,以后慢慢上传
包含UVA在线OJ系统的绝大部分的示例代码,并都已AC,可在刷题时参考
uva最全ac代码