求助一道题~~
usrbin吧
全部回复
仅看楼主
level 6

Two distinct positive integer numbers with decimal notations of the same length are called similar, if their decimal notations can be obtained from each other by permuting the digits.
How many numbers from the segment [l, r] have exactly one similar number in that segment?
Input
The input file contains two integer numbers l and r (1 ≤ l ≤ r ≤ 1015).
Output
Output one integer number — the sought amount.

2010年12月25日 07点12分 1
level 6
上面1015是10^15...
sample input
10 99
sample output
72
http://acm.sgu.ru/problem.php?contest=0&problem=420
2010年12月25日 07点12分 2
level 11
很粗糙的算法:
设Sn={(a1,a2..,an)|a1>=a2>=..>=an && n<=15 && 0<=ai<=9},可以算得|S1|+|S2|+...+|Sn|<4*10^6,这就可以做文章了[睡觉]
l前面补0拼成和r一样长度,设k=|r|.对于任意非负整数b=b1b2...bk,可以从左到右算出每个Sk排列<=b的数目f(b)。统计f(r)-f(l)=2的组合数再乘以2即可
算法时间复杂度O(4*10^6*15)

2010年12月25日 13点12分 3
level 11
应该是f(r)-f(l-1)=2[啊!]
2010年12月25日 13点12分 4
level 6
usrbin神犇大概看错题目了...我一开始也看错了...[88]
题目要求similar number(相似数)只能有一个,而且是在[L,R]范围内。
所以神马 f[R] - f[L-1] 这类的想法直接破碎 TwT[瘫坐]

2010年12月25日 13点12分 5
level 11
回复:5楼
没错啊?我要求的就是[L,R]里某个组合出现的数目f=f(R)-f(L-1),如果=2不就累加吗?[歪头]
2010年12月25日 13点12分 7
level 6
啊。。。对。。是这样。。但是怎么在O(k)的时间里算出在 <= b的个数?
2010年12月25日 13点12分 8
level 11
回复:8楼
考虑第i位,1-(i-1)位与b相同,[0,bi)的时候第i+1->第k位可以取任何数字,因此每个组合[c1,c2,..c10](c1+c2+..+c10)组合的数目=(k-i)!/pi(c[i]!),累加上去..
2010年12月25日 13点12分 9
level 11
回复:6楼
不过你这个方法显然比我的更好..WS我的吧
2010年12月25日 14点12分 10
level 6
我勒个去...这光头不是孟非么.....[揉脸]
2010年12月25日 14点12分 11
level 11
2010年12月25日 14点12分 12
level 14
[睡觉]我有更好的想法。。。
2010年12月26日 03点12分 13
level 6
蛋蛋姐赐教~
2010年12月26日 15点12分 14
level 6
问下java里面有自动排序且去掉重复数值的函数麽
2011年09月14日 08点09分 15
level 11
2011年09月14日 10点09分 17
1