Redian新闻
>
10秒之内,把蔡依林从这堆凤姐中找出来! (转)
avatar
10秒之内,把蔡依林从这堆凤姐中找出来! (转)# Joke - 肚皮舞运动
e*e
1
多谢lolhaha大牛指点,non-duplicate修订版如下。
client invoke: permute( new char[]{'a', 'b', 'c'}, 0 );
void permute(char[] perm, int level){
if ( level == perm.length ) {
System.out.println( new String( perm ) );
for ( int i = level, i < perm.length; i++ ) {
if ( level != i )
swap( perm, level, i );
permute( perm, level + 1 );
if ( level != i )
swap( perm, level, i );
}
}
void swap(char[] arr, int i, int j) {...}
avatar
F*o
2
提交了RFE,收到通知(网站上状态显示也是)说60天会出结果,但是现在超过60天了,
还是一点消息都没有,正常吗?谢谢啦
avatar
C*a
3
Need to do home inspection. Heard some inspectors can use infrared camera to
find out if a finished basement has water leakage. Just wondering if the
tool can find small damp area or very minor leakage. Can anyone comment on
the usefulness to inspect finished basement with infrared camera?
Thanks.
avatar
c*7
5
avatar
l*a
6
please change == to !=
thanks

【在 e****e 的大作中提到】
: 多谢lolhaha大牛指点,non-duplicate修订版如下。
: client invoke: permute( new char[]{'a', 'b', 'c'}, 0 );
: void permute(char[] perm, int level){
: if ( level == perm.length ) {
: System.out.println( new String( perm ) );
: for ( int i = level, i < perm.length; i++ ) {
: if ( level != i )
: swap( perm, level, i );
: permute( perm, level + 1 );
: if ( level != i )

avatar
F*a
7
不一定的,
call 他们试一下

【在 F*******o 的大作中提到】
: 提交了RFE,收到通知(网站上状态显示也是)说60天会出结果,但是现在超过60天了,
: 还是一点消息都没有,正常吗?谢谢啦

avatar
s*t
8
有点用处,但非常有限。 Inspector的经验更重要。
avatar
s*l
9
那个是蔡依林?感觉还不如凤姐
avatar
l*a
10
btw, seems 1 [] as parameter will be enough

【在 e****e 的大作中提到】
: 多谢lolhaha大牛指点,non-duplicate修订版如下。
: client invoke: permute( new char[]{'a', 'b', 'c'}, 0 );
: void permute(char[] perm, int level){
: if ( level == perm.length ) {
: System.out.println( new String( perm ) );
: for ( int i = level, i < perm.length; i++ ) {
: if ( level != i )
: swap( perm, level, i );
: permute( perm, level + 1 );
: if ( level != i )

avatar
a*r
11
众里寻她三五秒,眼眵睛转,那人却在行四列六笑。
avatar
e*e
12
Changed. Thanks.

【在 l*****a 的大作中提到】
: please change == to !=
: thanks

avatar
j*g
13
蔡本来就是个丑女,比凤姐强不了多少
avatar
e*e
14
Totally. arr and level could extract from function signature and become a
global variable outside of the function. Thank you!

【在 l*****a 的大作中提到】
: btw, seems 1 [] as parameter will be enough
avatar
l*o
15
20秒

【在 a*******r 的大作中提到】
: 众里寻她三五秒,眼眵睛转,那人却在行四列六笑。
avatar
l*a
16
no, for the logic inside the function,u don;t need arr

【在 e****e 的大作中提到】
: Totally. arr and level could extract from function signature and become a
: global variable outside of the function. Thank you!

avatar
i*0
17
双生?
avatar
e*e
18
按照permuation的规律交换arr中的两个元素?

【在 l*****a 的大作中提到】
: no, for the logic inside the function,u don;t need arr
avatar
e*e
19
多谢lolhaha大牛指点。很有收获。

【在 l*****a 的大作中提到】
: no, for the logic inside the function,u don;t need arr
avatar
a*l
20
你的最优是什么意思?速度最快?空间最小?程序代码最短?

【在 e****e 的大作中提到】
: 多谢lolhaha大牛指点。很有收获。
avatar
e*e
21
Time and space complexity. 没有其他解法能比这个解答, use less time and
space.

【在 a****l 的大作中提到】
: 你的最优是什么意思?速度最快?空间最小?程序代码最短?
avatar
c*t
22
我也才整明白,不容易想

【在 e****e 的大作中提到】
: 多谢lolhaha大牛指点。很有收获。
avatar
c*t
23
能不能和下面解法对比一下优缺点?
public static void permutation(String str) {
permutation("", str);
}
private static void permutation(String prefix, String str) {
int n = str.length();
if (n == 0) System.out.println(prefix);
else {
for (int i = 0; i < n; i++)
permutation(prefix + str.charAt(i), str.substring(0, i) + str.
substring(i+1, n));
}
}

【在 e****e 的大作中提到】
: Time and space complexity. 没有其他解法能比这个解答, use less time and
: space.

avatar
e*e
24
Time complexity is the same. The space complexity difference is huge. With
String, each recursion create two new strings. While with char array, it
only uses one copy of the char array throughout the program.

【在 c********t 的大作中提到】
: 能不能和下面解法对比一下优缺点?
: public static void permutation(String str) {
: permutation("", str);
: }
: private static void permutation(String prefix, String str) {
: int n = str.length();
: if (n == 0) System.out.println(prefix);
: else {
: for (int i = 0; i < n; i++)
: permutation(prefix + str.charAt(i), str.substring(0, i) + str.

avatar
c*t
25
是的。多谢!

【在 e****e 的大作中提到】
: Time complexity is the same. The space complexity difference is huge. With
: String, each recursion create two new strings. While with char array, it
: only uses one copy of the char array throughout the program.

avatar
a*l
26
时间上不好说,不过空间上这个解法是要用到递归的,不见得比非递归的算法更省空间
吧?理论上应该非递归的iterative算法最快最省空间,每次仅把必须换的字符换掉,
别的算法应该不可能效率更高吧?

【在 e****e 的大作中提到】
: Time and space complexity. 没有其他解法能比这个解答, use less time and
: space.

avatar
e*e
27
Thank you for your suggestion. I can see your point and 100% agree with you.
My question is how to implement the iterative solution. If the length is
fixed, we can do something like below. But if not, how to implement the
function void permute(char[] a) iteratively?
char[] arr = new char[]{'a', 'b', 'c'};
for ( int i = 0; i < 3; i++ ) {
for ( int j = 0; j < 3; j++ ) {
for ( int k = 0; k < 3; k++ ) {
if ( i != j && j != k && k != i )
System.out.println( arr[i] + arr[j] + arr[k] );
}
}
}

【在 a****l 的大作中提到】
: 时间上不好说,不过空间上这个解法是要用到递归的,不见得比非递归的算法更省空间
: 吧?理论上应该非递归的iterative算法最快最省空间,每次仅把必须换的字符换掉,
: 别的算法应该不可能效率更高吧?

avatar
p*2
28
用ruby练一下
a=[1,2,3]
p a.permutation.to_a
avatar
l*a
29
牛!!!

【在 p*****2 的大作中提到】
: 用ruby练一下
: a=[1,2,3]
: p a.permutation.to_a

avatar
l*a
30
所有二分的程序都是
Arrays.binarysearch()就搞定了吧?

【在 p*****2 的大作中提到】
: 用ruby练一下
: a=[1,2,3]
: p a.permutation.to_a

avatar
p*2
31

不好说吧?

【在 l*****a 的大作中提到】
: 所有二分的程序都是
: Arrays.binarysearch()就搞定了吧?

avatar
w*p
32
我一直以为你们在讨论P (n, m)的所有String. 原来是 P(n, n). 看起来code 很简洁,
很赞。我再学习下。
有两处typo:
1) if ( level == perm.length ) {
: System.out.println( new String( perm ) );
"}" is missing
2) for ( int i = level, i < perm.length; i++ ) {
=> for ( int i = level; i < perm.length; i++ ) {

【在 e****e 的大作中提到】
: 多谢lolhaha大牛指点。很有收获。
avatar
e*e
33
Thanks for your pointing out. I corrected it.

【在 w********p 的大作中提到】
: 我一直以为你们在讨论P (n, m)的所有String. 原来是 P(n, n). 看起来code 很简洁,
: 很赞。我再学习下。
: 有两处typo:
: 1) if ( level == perm.length ) {
: : System.out.println( new String( perm ) );
: "}" is missing
: 2) for ( int i = level, i < perm.length; i++ ) {
: => for ( int i = level; i < perm.length; i++ ) {

avatar
h*0
34
permutation用字典序比较好吧。 这个recursive空间复杂度太高了。。
avatar
e*e
35
what's 字典序? Details please. The space complexity is n. n is the length of
array. The length of the deepest recursion is also n.

【在 h*******0 的大作中提到】
: permutation用字典序比较好吧。 这个recursive空间复杂度太高了。。
avatar
e*e
36
多谢lolhaha大牛指点,non-duplicate修订版如下。
client invoke: permute( new char[]{'a', 'b', 'c'}, 0 );
void permute(char[] perm, int level){
if ( level == perm.length )
System.out.println( new String( perm ) );
for ( int i = level; i < perm.length; i++ ) {
if ( level != i )
swap( perm, level, i );
permute( perm, level + 1 );
if ( level != i )
swap( perm, level, i );
}
}
void swap(char[] arr, int i, int j) {...}
avatar
l*a
37
please change == to !=
thanks

【在 e****e 的大作中提到】
: 多谢lolhaha大牛指点,non-duplicate修订版如下。
: client invoke: permute( new char[]{'a', 'b', 'c'}, 0 );
: void permute(char[] perm, int level){
: if ( level == perm.length )
: System.out.println( new String( perm ) );
: for ( int i = level; i < perm.length; i++ ) {
: if ( level != i )
: swap( perm, level, i );
: permute( perm, level + 1 );
: if ( level != i )

avatar
l*a
38
btw, seems 1 [] as parameter will be enough

【在 e****e 的大作中提到】
: 多谢lolhaha大牛指点,non-duplicate修订版如下。
: client invoke: permute( new char[]{'a', 'b', 'c'}, 0 );
: void permute(char[] perm, int level){
: if ( level == perm.length )
: System.out.println( new String( perm ) );
: for ( int i = level; i < perm.length; i++ ) {
: if ( level != i )
: swap( perm, level, i );
: permute( perm, level + 1 );
: if ( level != i )

avatar
e*e
39
Changed. Thanks.

【在 l*****a 的大作中提到】
: please change == to !=
: thanks

avatar
e*e
40
Totally. arr and level could extract from function signature and become a
global variable outside of the function. Thank you!

【在 l*****a 的大作中提到】
: btw, seems 1 [] as parameter will be enough
avatar
l*a
41
no, for the logic inside the function,u don;t need arr

【在 e****e 的大作中提到】
: Totally. arr and level could extract from function signature and become a
: global variable outside of the function. Thank you!

avatar
e*e
42
按照permuation的规律交换arr中的两个元素?

【在 l*****a 的大作中提到】
: no, for the logic inside the function,u don;t need arr
avatar
e*e
43
多谢lolhaha大牛指点。很有收获。

【在 l*****a 的大作中提到】
: no, for the logic inside the function,u don;t need arr
avatar
a*l
44
你的最优是什么意思?速度最快?空间最小?程序代码最短?

【在 e****e 的大作中提到】
: 多谢lolhaha大牛指点。很有收获。
avatar
e*e
45
Time and space complexity. 没有其他解法能比这个解答, use less time and
space.

【在 a****l 的大作中提到】
: 你的最优是什么意思?速度最快?空间最小?程序代码最短?
avatar
c*t
46
我也才整明白,不容易想

【在 e****e 的大作中提到】
: 多谢lolhaha大牛指点。很有收获。
avatar
c*t
47
能不能和下面解法对比一下优缺点?
public static void permutation(String str) {
permutation("", str);
}
private static void permutation(String prefix, String str) {
int n = str.length();
if (n == 0) System.out.println(prefix);
else {
for (int i = 0; i < n; i++)
permutation(prefix + str.charAt(i), str.substring(0, i) + str.
substring(i+1, n));
}
}

【在 e****e 的大作中提到】
: Time and space complexity. 没有其他解法能比这个解答, use less time and
: space.

avatar
e*e
48
Time complexity is the same. The space complexity difference is huge. With
String, each recursion create two new strings. While with char array, it
only uses one copy of the char array throughout the program.

【在 c********t 的大作中提到】
: 能不能和下面解法对比一下优缺点?
: public static void permutation(String str) {
: permutation("", str);
: }
: private static void permutation(String prefix, String str) {
: int n = str.length();
: if (n == 0) System.out.println(prefix);
: else {
: for (int i = 0; i < n; i++)
: permutation(prefix + str.charAt(i), str.substring(0, i) + str.

avatar
c*t
49
是的。多谢!

【在 e****e 的大作中提到】
: Time complexity is the same. The space complexity difference is huge. With
: String, each recursion create two new strings. While with char array, it
: only uses one copy of the char array throughout the program.

avatar
a*l
50
时间上不好说,不过空间上这个解法是要用到递归的,不见得比非递归的算法更省空间
吧?理论上应该非递归的iterative算法最快最省空间,每次仅把必须换的字符换掉,
别的算法应该不可能效率更高吧?

【在 e****e 的大作中提到】
: Time and space complexity. 没有其他解法能比这个解答, use less time and
: space.

avatar
e*e
51
Thank you for your suggestion. I can see your point and 100% agree with you.
My question is how to implement the iterative solution. If the length is
fixed, we can do something like below. But if not, how to implement the
function void permute(char[] a) iteratively?
char[] arr = new char[]{'a', 'b', 'c'};
for ( int i = 0; i < 3; i++ ) {
for ( int j = 0; j < 3; j++ ) {
for ( int k = 0; k < 3; k++ ) {
if ( i != j && j != k && k != i )
System.out.println( arr[i] + arr[j] + arr[k] );
}
}
}

【在 a****l 的大作中提到】
: 时间上不好说,不过空间上这个解法是要用到递归的,不见得比非递归的算法更省空间
: 吧?理论上应该非递归的iterative算法最快最省空间,每次仅把必须换的字符换掉,
: 别的算法应该不可能效率更高吧?

avatar
p*2
52
用ruby练一下
a=[1,2,3]
p a.permutation.to_a
avatar
l*a
53
牛!!!

【在 p*****2 的大作中提到】
: 用ruby练一下
: a=[1,2,3]
: p a.permutation.to_a

avatar
l*a
54
所有二分的程序都是
Arrays.binarysearch()就搞定了吧?

【在 p*****2 的大作中提到】
: 用ruby练一下
: a=[1,2,3]
: p a.permutation.to_a

avatar
p*2
55

不好说吧?

【在 l*****a 的大作中提到】
: 所有二分的程序都是
: Arrays.binarysearch()就搞定了吧?

avatar
w*p
56
我一直以为你们在讨论P (n, m)的所有String. 原来是 P(n, n). 看起来code 很简洁,
很赞。我再学习下。
有两处typo:
1) if ( level == perm.length ) {
: System.out.println( new String( perm ) );
"}" is missing
2) for ( int i = level, i < perm.length; i++ ) {
=> for ( int i = level; i < perm.length; i++ ) {

【在 e****e 的大作中提到】
: 多谢lolhaha大牛指点。很有收获。
avatar
e*e
57
Thanks for your pointing out. I corrected it.

【在 w********p 的大作中提到】
: 我一直以为你们在讨论P (n, m)的所有String. 原来是 P(n, n). 看起来code 很简洁,
: 很赞。我再学习下。
: 有两处typo:
: 1) if ( level == perm.length ) {
: : System.out.println( new String( perm ) );
: "}" is missing
: 2) for ( int i = level, i < perm.length; i++ ) {
: => for ( int i = level; i < perm.length; i++ ) {

avatar
h*0
58
permutation用字典序比较好吧。 这个recursive空间复杂度太高了。。
avatar
e*e
59
what's 字典序? Details please. The space complexity is n. n is the length of
array. The length of the deepest recursion is also n.

【在 h*******0 的大作中提到】
: permutation用字典序比较好吧。 这个recursive空间复杂度太高了。。
avatar
b*7
60
字典序指的就是next permutation的顺序吧,从小到大。
如果有重复元素,要求不重复的permutation,这个方法就不适用了,那样什么又才是
最优解呢?
avatar
c*7
61
c# 来一个:
public static IEnumerable> P(IEnumerable list) {if (
list.Count() == 1)return new List> { list };return list.
Select((a, i1) => P(list.Where((b, i2) => i2 != i1)).Select(b => (new List> { a }).Union(b))).SelectMany(c => c);}
avatar
c*d
62
dedup is doable too using this approach. just check whether you've seen the
item before swapping.
here is javascript version.
function dedup_perm(a){
var solutions = [];
if (!a || a.length == 0) return [];
return dedup_perm_helper(a, 0);
function dedup_perm_helper(a, start) {
if(start == a.length) solutions.push(a.slice(0));
var seen = {};
for(var i = start; i < a.length; i++){
if (!seen[a[i]]) { // this line ensures no dup permutations.
seen[a[i]] = 1;
swap(a, start, i);
dedup_perm_helper(a, start + 1);
swap(a, start, i);
}
}
return solutions;
}

function swap(a, i, j){
var tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
console.log(dedup_perm([1,2,3,2]));
/// output ///
[ [ 1, 2, 3, 2 ],
[ 1, 2, 2, 3 ],
[ 1, 3, 2, 2 ],
[ 2, 1, 3, 2 ],
[ 2, 1, 2, 3 ],
[ 2, 3, 1, 2 ],
[ 2, 3, 2, 1 ],
[ 2, 2, 3, 1 ],
[ 2, 2, 1, 3 ],
[ 3, 2, 1, 2 ],
[ 3, 2, 2, 1 ],
[ 3, 1, 2, 2 ] ]

【在 b*******7 的大作中提到】
: 字典序指的就是next permutation的顺序吧,从小到大。
: 如果有重复元素,要求不重复的permutation,这个方法就不适用了,那样什么又才是
: 最优解呢?

avatar
j*x
63
又来调戏版友。。。

【在 p*****2 的大作中提到】
: 用ruby练一下
: a=[1,2,3]
: p a.permutation.to_a

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。