avatar
虚心问个问题:# PhotoGear - 摄影器材
L*Y
1
From the set of natural integer numbers
Let x = 1234 = {1, 2, 3, 4}
Let y = 2410 = {2, 4, 1, 0}
Write an algorithm to compute the rearrangement of x that is closest to y
but still greater than y. Both x and y have the same number of digits.
So in the example above, the answer would be { 2, 4, 1, 3 } = 2413 which is
greater than y = 2410 and closer than any other arrangements of x.
And whats the time complexity of this algorithm?
Any efficient algorithm?
avatar
j*o
2
我有些4x6inch的照片,hardcopy, 有没有什么办法把它们洗成大大的照片,质量还要
很好?比如16x20,或更大?
avatar
c*t
3
x是sorted吗? 不是的话,可以sort, 然后binary search each digit in y

is

【在 L****Y 的大作中提到】
: From the set of natural integer numbers
: Let x = 1234 = {1, 2, 3, 4}
: Let y = 2410 = {2, 4, 1, 0}
: Write an algorithm to compute the rearrangement of x that is closest to y
: but still greater than y. Both x and y have the same number of digits.
: So in the example above, the answer would be { 2, 4, 1, 3 } = 2413 which is
: greater than y = 2410 and closer than any other arrangements of x.
: And whats the time complexity of this algorithm?
: Any efficient algorithm?

avatar
x*g
4
有没有底片或者high resolution的digital原始文件?
没有的话估计没戏。
avatar
p*2
5
Treeset nlogn
avatar
j*o
6
没有。只有照片,hardcopy.

【在 x*****g 的大作中提到】
: 有没有底片或者high resolution的digital原始文件?
: 没有的话估计没戏。

avatar
L*Y
7
不是sort的。 可以展开说说?

【在 c********t 的大作中提到】
: x是sorted吗? 不是的话,可以sort, 然后binary search each digit in y
:
: is

avatar
x*g
8
那就没什么希望了...
可以放大,但是那就只能远观不可近玩了,呵呵

【在 j********o 的大作中提到】
: 没有。只有照片,hardcopy.
avatar
L*Y
9
怎么个做法? Treeset是java里面的?

【在 p*****2 的大作中提到】
: Treeset nlogn
avatar
d*x
10
这里的integer有范围吗?
例子里面都是0-9,但是看题目好像没有限制?

is

【在 L****Y 的大作中提到】
: From the set of natural integer numbers
: Let x = 1234 = {1, 2, 3, 4}
: Let y = 2410 = {2, 4, 1, 0}
: Write an algorithm to compute the rearrangement of x that is closest to y
: but still greater than y. Both x and y have the same number of digits.
: So in the example above, the answer would be { 2, 4, 1, 3 } = 2413 which is
: greater than y = 2410 and closer than any other arrangements of x.
: And whats the time complexity of this algorithm?
: Any efficient algorithm?

avatar
L*Y
11
就是0-9

【在 d**********x 的大作中提到】
: 这里的integer有范围吗?
: 例子里面都是0-9,但是看题目好像没有限制?
:
: is

avatar
d*x
12
先counting,把0-9的所有数字数一遍有多少
然后和第二个匹配,one by one
这样有两种情况,
1) 完全匹配,变成寻找next lexical order permutation,不提了
2) 到某个地方,set 1里面的数字不够了,这也有两种情况
i. set 1里面存在比当前set 2里面的数字大的,那么把最小的那个比set 2里面大的
添上,然后后面从小到大填
ii. set 1里面只剩下比当前set 2里面数字小的,这时候要从当前点往回走,把填进
去的数字再退回来,找到第一个位置,使得set 1里面的剩余数字中存在比set 2中的当
前数字大的,填进去,然后后面从小到大填。
如果最后发现set 1里面的数字无法比set 2大,输出异常。

is

【在 L****Y 的大作中提到】
: From the set of natural integer numbers
: Let x = 1234 = {1, 2, 3, 4}
: Let y = 2410 = {2, 4, 1, 0}
: Write an algorithm to compute the rearrangement of x that is closest to y
: but still greater than y. Both x and y have the same number of digits.
: So in the example above, the answer would be { 2, 4, 1, 3 } = 2413 which is
: greater than y = 2410 and closer than any other arrangements of x.
: And whats the time complexity of this algorithm?
: Any efficient algorithm?

avatar
p*2
13

嗯。就是这个思路。如果只是0-9, O(n)就可以了。

【在 d**********x 的大作中提到】
: 先counting,把0-9的所有数字数一遍有多少
: 然后和第二个匹配,one by one
: 这样有两种情况,
: 1) 完全匹配,变成寻找next lexical order permutation,不提了
: 2) 到某个地方,set 1里面的数字不够了,这也有两种情况
: i. set 1里面存在比当前set 2里面的数字大的,那么把最小的那个比set 2里面大的
: 添上,然后后面从小到大填
: ii. set 1里面只剩下比当前set 2里面数字小的,这时候要从当前点往回走,把填进
: 去的数字再退回来,找到第一个位置,使得set 1里面的剩余数字中存在比set 2中的当
: 前数字大的,填进去,然后后面从小到大填。

avatar
L*Y
14
很赞。

【在 d**********x 的大作中提到】
: 先counting,把0-9的所有数字数一遍有多少
: 然后和第二个匹配,one by one
: 这样有两种情况,
: 1) 完全匹配,变成寻找next lexical order permutation,不提了
: 2) 到某个地方,set 1里面的数字不够了,这也有两种情况
: i. set 1里面存在比当前set 2里面的数字大的,那么把最小的那个比set 2里面大的
: 添上,然后后面从小到大填
: ii. set 1里面只剩下比当前set 2里面数字小的,这时候要从当前点往回走,把填进
: 去的数字再退回来,找到第一个位置,使得set 1里面的剩余数字中存在比set 2中的当
: 前数字大的,填进去,然后后面从小到大填。

avatar
Y*f
15
思路很好啊。
可以把1)和2)ii合并
1.如果匹配完或者剩下的都比当前字符小,把剩下的字符的最大排列放到剩下的位置。
再用next permutation

【在 d**********x 的大作中提到】
: 先counting,把0-9的所有数字数一遍有多少
: 然后和第二个匹配,one by one
: 这样有两种情况,
: 1) 完全匹配,变成寻找next lexical order permutation,不提了
: 2) 到某个地方,set 1里面的数字不够了,这也有两种情况
: i. set 1里面存在比当前set 2里面的数字大的,那么把最小的那个比set 2里面大的
: 添上,然后后面从小到大填
: ii. set 1里面只剩下比当前set 2里面数字小的,这时候要从当前点往回走,把填进
: 去的数字再退回来,找到第一个位置,使得set 1里面的剩余数字中存在比set 2中的当
: 前数字大的,填进去,然后后面从小到大填。

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