HDU 1716 排列2 (格式问题+排列)
2016-06-03 13:06
375 查看
题意:。
析:我们完全可以STL里面的函数next_permutation(),然后方便,又简单,这个题坑就是在格式上。
行末不能有空格,结尾不能有空行,不大好控制,必须控制好第一次数。
这个题本应该用DFS的,去枚举,也挺简单的,在这就不说了。
代码如下:
析:我们完全可以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; }
相关文章推荐
- 阅读《构建之法》和以下链接的读后感
- Ajax聊天
- STORM_0009_Lifecycle-of-a-topology/拓扑的生命周期
- 安装ubuntu 12.04 samba图形界面
- Codeforces677B
- HDU 1238 Substrings (最长公共子串+DFS)
- 简单总结C语言中的运算符优先级
- java定时任务接口ScheduledExecutorService
- dpkg命令的用法
- java定时任务(三):timerTask定时任务
- 【Android基础】应用资源
- 使用反射将DataTable的数据转成实体类
- 使用IE打开WEBDYNPRO时,报错 RABAX_STATE
- iOS开发UI篇—Quartz2D简单介绍
- JAVA程序执行顺序
- 模板及常用函数总结
- 成员函数的重载,覆盖与隐藏
- C语言运算符及其优先级汇总表口诀
- Mongodb 安装过程与服务无法启动100、48问题
- 如何在PowerPiont里面裁剪图片?