poj 1731 Orders(暴力)
题目链接: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(暴力)的更多相关文章
- poj 1731 Orders
http://poj.org/problem?id=1731 Orders Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9 ...
- POJ 1731 Orders(STL运用)
题目地址:POJ 1731 这题能够直接用STL函数做,非常轻松..next_permutation函数非常给力.. 代码例如以下: #include <algorithm> #inclu ...
- Orders POJ - 1731
The stores manager has sorted all kinds of goods in an alphabetical order of their labels. All the k ...
- POJ 1731:Orders
Orders Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9940 Accepted: 6048 Descriptio ...
- poj 2363 Blocks(暴力)
题目链接:http://poj.org/problem?id=2363 思路分析:由于数据较小,采用暴力搜索法.假设对于矩形边长 1 <= a <= b <= c <= N; ...
- POJ 2029 DP || 暴力
在大矩形中找一个小矩形 使小矩形包括的*最多 暴力或者DP 水题 暴力: #include "stdio.h" #include "string.h" int ...
- POJ 2912 Rochambeau(暴力)+【带权并查集】
<题目链接> 题目大意: n个人进行m轮剪刀石头布游戏(0<n<=500,0<=m<=2000),接下来m行形如x, y, ch的输入,ch='='表示x, y平局 ...
- POJ 2912 - Rochambeau - [暴力枚举+带权并查集]
题目链接:http://poj.org/problem?id=2912 Time Limit: 5000MS Memory Limit: 65536K Description N children a ...
- POJ 3414 Pots 暴力,bfs 难度:1
http://poj.org/problem?id=3414 记录瓶子状态,广度优先搜索即可 #include <cstdio> #include <cstring> #inc ...
随机推荐
- 保存android程序崩溃日志到SD卡
private boolean writeToSDCard(Throwable ex) { boolean isDealing = false; if (Environment.getExternal ...
- GDB调试之core文件(如何定位到Segment fault)
core dump又叫核心转储,当程序运行过程中发生异常,程序异常退出时,由操作系统把程序当前的内存状况存储在一个core文件中,叫core dump.(内部实现是:linux系统中内存越界会收到SI ...
- 关于ue上传图片到七牛云设置key
多图上传设置key: dialogs文件下面,image文件下面的image.html,链接webuploader.js,不链接webuploader.min.js webuploader.js里面 ...
- asp.net中实现MD5加密、解密的方法
这个MD5加密.解密的方法会使用即可. 使用时的代码备忘:Response.Write(FormsAuthentication.HashPasswordForStoringInConfigFile(& ...
- JS学习之闭包的理解
一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域.变量的作用域无非就是两种:全局变量和局部变量.Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量.另 ...
- [LeetCode]题解(python):002-Add Two Numbers
题目来源: https://leetcode.com/problems/add-two-numbers/ 题意分析: 这道题目是要将两个单链条相加.输出得到的新链条. 题目思路: 不难发现,其实题目就 ...
- 如何使用robots不让百度和google收录
如何使用robots不让百度和google收录 有没有想过,如果我们某个站点不让百度和google收录,那怎么办? 搜索引擎已经和我们达成一个约定,如果我们按约定那样做了,它们就不要收录. 这个写 ...
- BZOJ 1008 越狱 (组合数学)
题解:正难则反,从总数中减去全部相邻不相同的数目就是答案,n*(n-1)^(m-1):第一个房间有n中染色方案,剩下m-1个房间均只有n-1种染色方案,用总数减就是答案. #include <c ...
- C++模板:字典树
//插入 void insert(char *s,char *s1){ for(int l=strlen(s),x=0,i=0;i<l;i++){ if(!trie[x].son[s[i]-'a ...
- DRP过后,感受知识间的通性
DRP视频看了不短的时间,真正开始DRP的时间是7月17号,至今两个月了.由于暑假期间英语的学习占得时间比较多,所以DRP视频进行的很慢.9月11号看完了DRP所有的视频,这个项目完成后最大的感受是: ...