您的位置:首页 > 其它

HDU 1716 排列2 (格式问题+排列)

2016-06-03 13:06 375 查看
题意:。

析:我们完全可以STL里面的函数next_permutation(),然后方便,又简单,这个题坑就是在格式上。

行末不能有空格,结尾不能有空行,不大好控制,必须控制好第一次数。

这个题本应该用DFS的,去枚举,也挺简单的,在这就不说了。

代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <map>
#include <cctype>

using namespace std;
const int maxn = 1000 + 5;
int a[5];

int main(){
//    freopen("in.txt", "r", stdin);
int kase = 0;
while(true){
int sum = 0;
for(int i = 0; i < 4; ++i){
scanf("%d", &a[i]);
sum += a[i];
}
if(!sum)  break;
if(kase)  printf("\n");
sort(a, a+4);

int t = -1;
bool ok = false;
do{
if(!a[0])  continue;

if(a[0] != t){
t = a[0];
if(ok)  printf("\n");
ok = true;
}
else  printf(" ");

for(int i = 0; i < 4; ++i)
printf("%d", a[i]);
}while(next_permutation(a, a+4));

printf("\n");
++kase;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: