题目链接:http://poj.org/problem?id=1731

思路分析:含有重复元素的全排列问题;元素个数为200个,采用暴力枚举法。

代码如下:

#include <iostream>
#include <algorithm>
using namespace std; const int MAX_N = + ;
void PrintPermu( int n, char P[], char A[], int cur )
{
int i, j; if ( cur == n )
{
for ( i = ; i < n; ++i )
cout << A[i];
cout << endl;
}
else
{
for ( int i = ; i < n; ++i )
{
if ( i == || P[i] != P[i-] )
{
int c1 = , c2 = ; for ( j = ; j < cur; ++j )
if ( A[j] == P[i] ) c1++;
for ( j = ; j < n; ++j )
if ( P[i] == P[j] ) c2++; if ( c1 < c2 )
{
A[cur] = P[i];
PrintPermu( n, P, A, cur + );
}
}
}
}
} int main()
{
char P[MAX_N], A[MAX_N]; cin >> P;
sort( P, P + strlen(P) );
PrintPermu( strlen(P), P, A, );
return ;
}

poj 1731 Orders(暴力)的更多相关文章

  1. poj 1731 Orders

    http://poj.org/problem?id=1731 Orders Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9 ...

  2. POJ 1731 Orders(STL运用)

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

  3. Orders POJ - 1731

    The stores manager has sorted all kinds of goods in an alphabetical order of their labels. All the k ...

  4. POJ 1731:Orders

    Orders Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9940   Accepted: 6048 Descriptio ...

  5. poj 2363 Blocks(暴力)

    题目链接:http://poj.org/problem?id=2363 思路分析:由于数据较小,采用暴力搜索法.假设对于矩形边长 1 <= a <= b <= c <= N; ...

  6. POJ 2029 DP || 暴力

    在大矩形中找一个小矩形 使小矩形包括的*最多 暴力或者DP  水题 暴力: #include "stdio.h" #include "string.h" int ...

  7. POJ 2912 Rochambeau(暴力)+【带权并查集】

    <题目链接> 题目大意: n个人进行m轮剪刀石头布游戏(0<n<=500,0<=m<=2000),接下来m行形如x, y, ch的输入,ch='='表示x, y平局 ...

  8. POJ 2912 - Rochambeau - [暴力枚举+带权并查集]

    题目链接:http://poj.org/problem?id=2912 Time Limit: 5000MS Memory Limit: 65536K Description N children a ...

  9. POJ 3414 Pots 暴力,bfs 难度:1

    http://poj.org/problem?id=3414 记录瓶子状态,广度优先搜索即可 #include <cstdio> #include <cstring> #inc ...

随机推荐

  1. 启用Spring quartz定时器,导致tomcat服务器自动停止

    在项目中添加了一个定时功能,基于Spring quartz: 设置好执行时间后(如:每天14:00) 当程序执行完后,就会出现以下信息: 2013-7-22 11:36:02 org.apache.c ...

  2. C#DB2开发问题随记

    最近公司有个小工具需要用到DB2数据库,以前没玩过DB2,觉得应该很容易就实现了. 这个小工具最开始用了Nhibernate来连接DB2,Nhibernate也是第一次用..实在是惭愧啊... 第一次 ...

  3. BZOJ 2440 完全平方数(莫比乌斯反演+二分查找)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=23362 题意:定义含有平方数因子的数为完全平方数(平方数因子不包含 ...

  4. BZOJ 3224: Tyvj 1728 普通平衡树(BST)

    treap,算是模板题了...我中间还一次交错题... -------------------------------------------------------------------- #in ...

  5. SQL Server 取前一天的0点和23点59分59秒

    DECLARE @startDate1 DATE; DECLARE @startDate DATETIME; ,@startDate1); ,CONVERT(DATETIME,@startDate1) ...

  6. cocos2d-x中的CCScrollView滑动体验不佳

    在最近的项目中,使用了Cocos2d-x (2.2.0版本)提供的CCScrollView来拖动一个比较大的画面,但是发现滑动体验非常不佳, 手指离开屏幕后,滑动没有惯性,一个不算太大的画面,要滑动好 ...

  7. Bandwidthd+Postgresql数据库配置笔记

    Bandwidthd+Postgresql数据库配置笔记 本系列文章由ex_net(张建波)编写,转载请注明出处. http://blog.csdn.net/zjianbo/article/detai ...

  8. 视频(其他)下载+tomcat 配置编码+图片上传限制大小

    视频下载:前台 jsp function downVideo(value,row,index){ return '<a href="<%=basePath%>admin/v ...

  9. Linux下 保存 git账号密码

    一.通过文件方式 1.在~/下, touch创建文件 .git-credentials, 用vim编辑此文件,输入内容格式: touch .git-credentials vim .git-crede ...

  10. php ajax提交数据 在本地可以执行,而在服务器不能执行

    1.排除是服务器的问题 把单独的ajax项目传到服务器上,可以正常返回xml数据 2.排除是项目下的限制问题 把单独的ajax放在相应的项目文件夹下,单独访问该ajax发送数据的页面,能够正常执行 3 ...