Sudoku bjfu1004 全排列
来源:互联网 发布:过量运动的危害数据 编辑:程序博客网 时间:2024/05/22 00:32
描述
Ben is writing a small game Sudoku.But he finds it hard to produce a resonable
matrix for a new game.So he asks you for help.
To make the problem easier, we can only generate a line of the matrix.
There are 362880 different kinds of line from 123456789 to 987654321.
In this problem,we regard 123456789 as the first line,regard 123456798
as the second line, and so on.
输入
The input consists of multiple test cases. Each test case consists of an integer n(0<n<=362880). Process to the end of file.
输出
For each test case, print the nth line.
样例输入
1
2
3
362880
样例输出
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 9 8
1 2 3 4 5 6 8 7 9
9 8 7 6 5 4 3 2 1
#include <iostream>#include <algorithm>using namespace std;#define MAX 362888int main(){int n,count,i;while (scanf("%d",&n)!=EOF){int a[]={1,2,3,4,5,6,7,8,9};for (count=1;count<n;count++)next_permutation(a,a+9);for (i=0;i<8;i++)printf("%d ",a[i]);printf("%d\n",a[8]);} return 0;}
利用next_permutation函数求全排列,使用样例:
#include <cstdio>#include <algorithm>#include <cstring>#define MAX 100 using namespace std; int main(){ int length; char str[MAX]; gets(str); length = strlen(str); sort(str, str + length); puts(str); while (next_permutation(str, str + length)) { puts(str); } return 0;}
- Sudoku bjfu1004 全排列
- bjfu1004 Sudoku
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- 全排列
- Sql: 去除字符串中的相同的字符串函數
- 位运算(1)
- Win7安装Inventor的向导InventorWizards提示错误error code 2738的解决办法
- Linux系统之间文件传输命令
- 动态3D立方体(OpenGL图形编程)
- Sudoku bjfu1004 全排列
- 特征提取
- linux开发常用的工具
- wztooltip - 鼠标移动到某标签显示内容(支持html)
- NetAdvantage.for.NET.2008.Vol.2.CLR3.5注册码不正确的处理方法 win2008R2 64位系统
- 【Text】 —— 极限研究
- 禁止某些用户使用ssh 远程登录
- 启动Activity的两种方式
- PowerDesigner与Eclipse同步开发