Humble Numbers USCAO chapter 3.1
生活随笔
收集整理的這篇文章主要介紹了
Humble Numbers USCAO chapter 3.1
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?...目測我自己寫坑定超時,就去NOCOW看了下,題解,官方是每個質數與已有的humble想乘取大于最大humble的最小數即是新的最大humble,
然后我就寫了個個,開始嫌麻煩用set存,超時的飛起。然后全部改成數組,結果case 6還是超時,想了半天感覺和別人的題解也沒啥差別,為什么運行時間差這么多
后來試著把69行的循環初始條件改成i=0,改成i=1,瞬間過了....后來一想確實i=0 沒用啊,而且case 6求第100000個,白白循環100000次....
?
?
?
1 /* 2 3 ID: hubiao cave 4 5 PROG: humble 6 7 LANG: C++ 8 9 */ 10 11 12 13 14 #include<iostream> 15 16 #include<fstream> 17 #include<algorithm> 18 #include<set> 19 #include<cstring> 20 21 using namespace std; 22 23 24 25 26 int main() 27 28 { 29 30 ifstream fin("humble.in"); 31 ofstream fout("humble.out"); 32 int prim[102]; 33 int humble[100002]; 34 35 int more[102]; 36 37 memset(humble,0,100002*4); 38 memset(prim,0,102*4); 39 40 41 int lastInd[102]; 42 for(int i=0;i<102;i++) 43 lastInd[i]=0; 44 45 int cnt,number,temp; 46 int hlen=0; 47 fin>>cnt>>number; 48 for(int i=0;i<cnt;++i) 49 { 50 fin>>temp; 51 prim[i]=temp; 52 } 53 prim[cnt]=1; 54 sort(prim,prim+cnt+1); 55 humble[0]=1; 56 hlen++; 57 58 59 60 while(hlen<=number) 61 { 62 63 int lasthumber=humble[hlen-1]; 64 int cnt1=0; 65 int* pmin=0; 66 int mcnt=0; 67 68 69 for(int i=1;i<=cnt;i++) 70 { 71 72 for(int j=lastInd[cnt1];j<hlen;j++) 73 { 74 if(prim[i]*humble[j]>lasthumber) 75 { 76 more[mcnt++]=prim[i]*humble[j]; 77 lastInd[cnt1]=j; 78 break; 79 } 80 81 } 82 cnt1++; 83 } 84 85 pmin=min_element(more,more+mcnt); 86 humble[hlen++]=*pmin; 87 88 } 89 90 fout<<humble[hlen-1]<<endl; 91 92 return 0; 93 94 95 }?
轉載于:https://www.cnblogs.com/cavehubiao/p/3337832.html
總結
以上是生活随笔為你收集整理的Humble Numbers USCAO chapter 3.1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android 超级工具类
- 下一篇: 用python完成《商务与经济统计(第1