Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我也发个In Reply To:Re:终于过了,发个程序给和我一样郁闷的人参考一下 Posted by:wangguanjin at 2005-09-04 00:14:30 #include <stdio.h> #include <math.h> #define pi 3.1415926535897932384626L #define dx 0.0002L int N,M; int point[151][2]; void init() { int i; for(i=0;i<=150;i++) { point[i][0] = point[i][1] = 0; } } double f1(double t) { double c = 1.0 / sqrt(2.0*pi),d = exp(-t*t / 2.0); return c * d; } double f2(double t) { double c = 1.0 / sqrt(2.0*pi),d = exp(-t*t / 2.0); return c * d; } int computer(int code) { double x,y; int i,sum = 0; for(i=0;i<code;i++) sum += point[i][1]; y = double(sum) / double(N); // printf("y:%lf\n",y); if(y>=0.50) { y = y - 0.50; x = 0; double tempy = 0.0; int k = 1; while(true) { tempy += (f1( (k-1)*dx ) + f1( k*dx )) * dx * 0.5; if(tempy + 0.000000001 >= y ){ x = dx * (k+k-1) * 0.5; break;} k++; } // printf("x:%lf\n",x); } else { y = 0.50 - y; x = 0; double tempy = 0.0; int k = 1; while(true) { tempy += (f2( (k-1)*dx ) + f2( k*dx )) * dx * 0.5; if(tempy + 0.000000001 >= y ) { x = -1.0 * dx * (k+k-1) * 0.5; break; } //printf("x:%.20lf\n",-1.0 * dx * (k+k-1) * 0.5); // printf("tempy:%0.20lf k:%d %.40lf\n",tempy,k,(f2( (k-1)*dx ) + f2( k*dx )) * dx * 0.5); k++; } // printf("x:%lf\n",x); } if(500.0 + 100.0 * x <= 100.0) return 100; else if(500.0 + 100.0 * x > 100.0 && 500.0 + 100.0 * x <= 501.0) return int(500.0 + 100.0 * x); else if(500.0 + 100.0 * x > 501.0 && 500.0 + 100.0 * x <= 900.0) { if (500.0 + 100.0 * x > int(500.0 + 100.0 * x)) return int(500.0 + 100.0 * x) + 1; else return int(500.0 + 100.0 * x); //note note note again!!!!! } else return 900; } int main(void) {//printf("%.20lf\n",(1.0 / sqrt(2.0*pi)) * exp(0.01*0.01 / 2.0)); int i,code; while(true) { scanf("%d",&N); if(!N) break; init(); for(i=0;i<N;i++) { scanf("%d",&code); if( !point[code][0] ) { point[code][0] = code; point[code][1]++; } else { point[code][1]++; } } scanf("%d",&M); for(i=0;i<M;i++) { scanf("%d",&code); printf("%d\n",computer(code)); } printf("\n"); }//while return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator