BJFU 1004——Sudoku



描述

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


本题最初我的想法是把输入的值每一位都拆开,这样可以确定每一个值所应对应的值,略微试了一下,此方法太过复杂,可能还会出现各种稀奇古怪的bug,所以果断放弃。

看到邹神代码,活捉一只next_permutation,如法炮制问了度娘,本题就A了,不过时间上惨不忍睹2745MS。

后来把数组改到函数内,提高到2698MS,还是丑的不行。

之后吧do_while改成了for,效率明显上升,到了889MS。

后来突然想到,既然有next_permutation,那为何不可有prev_permutation,二话不说度娘走起,果然又活捉一只新鲜的prev_permutation。

吼吼,时间就提到93MS。

目前还没想到更好的解法,但应该是有的,毕竟有这么多个0MS的解答,看来我的还是略丑,下次回看这题再想一下呗!!!



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值