bjfu1004 Sudoku

18 篇文章 1 订阅
3 篇文章 0 订阅

Sudoku

Time Limit(C/C++):3000MS/5000MS          Memory Limit:65536KByte
Total Submit:509            Accepted:266

Description

Ben is writing a small game Sudoku.But he finds it hard to produce a reasonable
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.

Input

The input consists of multiple test cases. Each test case consists of an integer n(0<n<=362880). Process to the end of file.

Output

For each test case, print the nth line.

Sample Input

1
2
3
362880

Sample Output

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

Hint

参考课件中【枚举排列】的方法,建议使用STL中next_permutation函数。

Source

ben


简单next_permutation函数用法

AC代码:

#include<iostream> 
#include<algorithm>  
using namespace std; 
#include<stdio.h> 
int main() 
{ 
int n,i; 
    while(scanf("%d",&n)!=EOF) 
    { 
        char a[9]={'1','2','3','4','5','6','7','8','9'},ch; 
        while(--n) 
                  next_permutation(a,a+9); 
        for(i=0;i<8;i++) 
            printf("%c ",a[i]);         
        printf("%c\n",a[8]); 
    } 
    return 0; 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值