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 ...
随机推荐
- Arcgis for javascript不同的状态下自己定义鼠标样式
俗话说:爱美之心.人皆有之. 是的.没错,即使我仅仅是一个做地图的,我也希望自己的地图看起来好看一点. 在本文,给大家讲讲在Arcgis for javascript下怎样自己定义鼠标样式. 首先.说 ...
- codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- xml 充当简易数据库
后台: 写入节点 public static void Update(string path, string node, string attribute, string value) { try { ...
- 行内元素有哪些?块级元素有哪些?CSS的盒模型?转载
块级元素:div p h1 h2 h3 h4 form ul行内元素: a b br i span input selectCss盒模型:内容,border ,margin,padding css中的 ...
- offsetParent 到底是哪一个?
前言 温故而知新.遇到offsetParent这个知识点,发现书上讲的不够详细.于是看了看豪情的博客,发现讲得很具体,收藏一下. 正文 不同情况 没有已定位的父节点,且自身position:relat ...
- ##DAY6 UIScrollView
##DAY6 UIScrollView #pragma mark ———————UIScrollView——————————— 属性: contentSize 内容滚动范围 contentOffset ...
- C/C++修改常量的值
C/C++中常量修饰const可以用来保证一些确定的量不会被一不小心改变,比如PI,一直是3.14159...... 但是不排除有时候也会需要修改常量的值,通过直接修改是不能达到目的. 比如: #in ...
- ssh免密钥登录
说明:下文中说的 '客户端'指的是你所使用的本地机器; '服务端'指的是远程你要连接的机器; ----------------------------------------------------- ...
- Flex 百度地图API使用
今天想看一下Flex中关于地图方面的使用,刚开始看了google map api, 感觉用起来挺麻烦,关键是英文不好,文档读起来费劲,还有密钥神马的~ 那我就试验一下百度地图的接口,文档是中文的. 首 ...
- Intersection(poj)
Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13140 Accepted: 3424 Des ...