|
|
вернуться в форумrandom algorithm this is my code: #include<stdio.h> #include<stdlib.h> #include<math.h> int main() { long K[5000005],N,i,j,t,value,k,count,a,flag; scanf ("%ld",&N); if (N%2==0) k=N/2; else k=N/2+1; for (i=0;i<N;i++) scanf("%ld",&K[i]); for(i=0;i<N;i++){ j=rand()%N; for(flag=0,count=1,t=0;t<N;t++){ if (K[t]==K[j]) count++; if (count>=k){ value=K[j]; flag=1; break; } } if (flag=1) break; } printf("%ld\n",value); return 0; } why Crash (stack overflow)? please help me ? Re: random algorithm define big arrays outside procedures long K[5000005] Re: random algorithm I modify small than long K[5000005] to k[500005],but it Crash (stack overflow)? Re: random algorithm change you prog to -------------- long K[5000005] int main() { long N,i,j,t,value,k,count,a,flag; scanf ("%ld",&N); ------------ or use #pragma comment(linker, "/STACK:16777216") defaut stack size ~1mb Re: random algorithm Edited by author 29.12.2007 01:18 Re: random algorithm Thanks ( KIRILL(ArcSTUpid coder:) )to solve problem of memory for me,but now answer is wrong; could you mail to me for 1510?
email: k13795263@126.com thanks; Re: random algorithm The problem in rand(); See documentation for return value. It's too small. You need something like this: t = (rand()*rand())%N; |
|
|