亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
樓主: yzc2002
打印 上一主題 下一主題

據(jù)說是google的面試題,看誰的快 [復(fù)制鏈接]

論壇徽章:
0
21 [報(bào)告]
發(fā)表于 2006-03-29 17:08 |只看該作者
原帖由 flw 于 2006-3-29 17:04 發(fā)表
還有個(gè)問題,什么叫做“下一個(gè)最大的”?
難道這個(gè)是有最大值的?

有最大值的啊
我給的結(jié)果就是全集

論壇徽章:
0
22 [報(bào)告]
發(fā)表于 2006-03-29 17:12 |只看該作者
原帖由 yzc2002 于 2006-3-29 17:08 發(fā)表

有最大值的啊
我給的結(jié)果就是全集

只是部分?jǐn)?shù)據(jù)的全集
呵呵

論壇徽章:
0
23 [報(bào)告]
發(fā)表于 2006-03-29 17:13 |只看該作者
原帖由 b46 于 2006-3-29 17:12 發(fā)表

只是部分?jǐn)?shù)據(jù)的全集
呵呵

什么意思?
就是說除了我列出的數(shù)外,不可能有別的解了,所以叫全集

論壇徽章:
0
24 [報(bào)告]
發(fā)表于 2006-03-29 17:16 |只看該作者
原帖由 yzc2002 于 2006-3-29 17:13 發(fā)表

什么意思?
就是說除了我列出的數(shù)外,不可能有別的解了,所以叫全集

你證明過了?

論壇徽章:
0
25 [報(bào)告]
發(fā)表于 2006-03-29 17:18 |只看該作者
最笨的辦法,
PS: 運(yùn)行環(huán)境為在windows xp下 vs2005 cl.exe compiler,默認(rèn)編譯/優(yōu)化選項(xiàng) release binary
amd sempron2800 + 512M,。龋泄P記本
findallone(100)時(shí),沒算出,等了2分鐘,cpu100% 


  1. #include "stdafx.h"
  2. #include "windows.h"


  3. int findone(long t)
  4. {
  5.         int theunit = 0;
  6.         int count = 0;
  7.         while(t>0)
  8.         {
  9.                 theunit = t%10;
  10.                 if(theunit == 1)
  11.                         count++;
  12.                 t = t/10;
  13.         }
  14.         return count;
  15. }

  16. void findallone(int count)
  17. {
  18.         DWORD time = 0;
  19.         long n =13;
  20.         long sumofone=6;
  21.         int i = 0;
  22.         for( ; i<count; i++)
  23.         {
  24.                 time = GetTickCount();
  25.                 while(n != sumofone)
  26.                 {
  27.                         n++;
  28.                         sumofone += findone(n);
  29.                 }
  30.                 time = GetTickCount()-time;
  31.                 printf("%3d: need time:%5d; the value:%d\n",i+1,time, n);
  32.                 n++;
  33.                 sumofone += findone(n);
  34.         }
  35.         return ;
  36. }

  37. int _tmain(int argc, _TCHAR* argv[])
  38. {
  39.        
  40.         findallone(40);               
  41.         return 0;
  42. }
復(fù)制代碼


結(jié)果:
1: need time:    0; the value:199981
2: need time:    0; the value:199982
3: need time:    0; the value:199983
4: need time:    0; the value:199984
5: need time:    0; the value:199985
6: need time:    0; the value:199986
7: need time:    0; the value:199987
8: need time:    0; the value:199988
9: need time:    0; the value:199989
10: need time:    0; the value:199990
11: need time:    0; the value:200000
12: need time:    0; the value:200001
13: need time:   62; the value:1599981
14: need time:    0; the value:1599982
15: need time:    0; the value:1599983
16: need time:    0; the value:1599984
17: need time:    0; the value:1599985
18: need time:    0; the value:1599986
19: need time:    0; the value:1599987
20: need time:    0; the value:1599988
21: need time:    0; the value:1599989
22: need time:    0; the value:1599990
23: need time:   78; the value:2600000
24: need time:    0; the value:2600001
25: need time: 1172; the value:13199998
26: need time: 2469; the value:35000000
27: need time:    0; the value:35000001
28: need time:   31; the value:35199981
29: need time:    0; the value:35199982
30: need time:    0; the value:35199983
31: need time:    0; the value:35199984
32: need time:    0; the value:35199985
33: need time:    0; the value:35199986
34: need time:    0; the value:35199987
35: need time:    0; the value:35199988
36: need time:    0; the value:35199989
37: need time:    0; the value:35199990
38: need time:    0; the value:35200000
39: need time:    0; the value:35200001
40: need time: 9750; the value:117463825

論壇徽章:
0
26 [報(bào)告]
發(fā)表于 2006-03-29 17:22 |只看該作者
原帖由 b46 于 2006-3-29 17:16 發(fā)表

你證明過了?

是的,有興趣的話我貼上來吧
說實(shí)話,打這個(gè)東西可不容易啊~~

count1.JPG (100.74 KB, 下載次數(shù): 113)

count1.JPG

論壇徽章:
0
27 [報(bào)告]
發(fā)表于 2006-03-29 17:23 |只看該作者
原帖由 yzc2002 于 2006-3-29 17:22 發(fā)表

是的,有興趣的話我貼上來吧
說實(shí)話,打這個(gè)東西可不容易啊~~

呵呵
沒想到這樣把答案騙到了,意外
不管怎么樣,拿回家研究研究
多謝了

論壇徽章:
0
28 [報(bào)告]
發(fā)表于 2006-03-29 17:24 |只看該作者
如果能看懂上面的證明,那下面的這個(gè)程序就很自然了
  1. long long f(long long n)
  2. {
  3.     int k;
  4.     long long e, m = n, r;
  5.     if(n <= 1) return n;
  6.     for(k=0, e=1; m >= 10; k++, e *= 10) m /= 10;
  7.     r = n - m*e;
  8.     if(m == 1)
  9.         return(e/10*k+r+1+f(r));
  10.     else
  11.         return(e/10*k*m+e+f(r));
  12. }

  13. int digit_num(long long n)
  14. {
  15.     int k;
  16.     for(k=0; n > 0; k++) n /= 10;
  17.     return k;
  18. }

  19. int main()
  20. {
  21.     int k;
  22.     long long n, v;
  23.     for(n = 1; n<10000000000;)
  24.     {
  25.         v = f(n);
  26.         if(v == n) {
  27.             printf("%lld\n", n);
  28.             n++;
  29.         }
  30.         else if(v > n) n = v;
  31.         else {
  32.             k = digit_num(n + n - v);
  33.             n += (n-v)/k + 1;
  34.         }
  35.     }
  36. }
復(fù)制代碼

[ 本帖最后由 yzc2002 于 2006-4-3 12:49 編輯 ]

評分

參與人數(shù) 1可用積分 +5 收起 理由
converse + 5 大哥,我給你加分哈 ..

查看全部評分

論壇徽章:
0
29 [報(bào)告]
發(fā)表于 2006-03-29 17:24 |只看該作者
原帖由 b46 于 2006-3-29 17:23 發(fā)表

呵呵
沒想到這樣把答案騙到了,意外
不管怎么樣,拿回家研究研究
多謝了

:em12::em12::em12:

論壇徽章:
0
30 [報(bào)告]
發(fā)表于 2006-03-29 17:30 |只看該作者
原帖由 yzc2002 于 2006-3-29 17:24 發(fā)表

:em12::em12::em12:

智者千慮,必有一失
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP