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 |
Re:你换C++交看看 貌似我当时就是C++可以过,G++wa,可能有精度问题...In Reply To:wa死了!!冰天雪地裸地跪求高手指正错误!!! Posted by:testSky at 2007-03-23 12:05:22 > #include <stdio.h> > #include <stdlib.h> > > long buf[100000]; > int countElement=0; > int K; > > const int isEqual=0; > const int tooSmall=1; > const int tooLarge=2; > > int iterative(long l){ > int total=0; > int i; > for(i=0;i<countElement;i++){ > total+=buf[i]/l; > } > if(total>K) > return tooLarge; > else if(total==K){ > return isEqual; > }else > return tooSmall; > } > int main(){ > int N; > int i,j,tag,result; > char tmp[30]; > char* ptr; > long min,a,b,l,sum; > scanf("%d %d",&N,&K); > > min=1000000; > sum=0; > for(i=0;i<N;i++){ > memset(tmp,0,sizeof(tmp)); > scanf("%s",&tmp); > ptr=strchr(tmp,'.'); > strncpy(ptr,ptr+1,2); > ptr[2]='\0'; > buf[countElement]=atol(tmp); > if(min>buf[countElement]){ > min=buf[countElement]; > } > sum+=buf[countElement]; > countElement++; > > } > int store=0; > if(sum<K){ > result=0; > }else{ > a=1; > b=min; > result=0; > while(a<=b){ > l=(a+b)/2; > if(l==0){ > break; > } > tag=iterative(l); > if(tag==isEqual){ > result=l; > a=l+1; > }else if(tag==tooLarge){ > a=l+1; > result=l; > }else if(tag==tooSmall){ > b=l-1; > } > } > } > printf("%.2lf\n",(double)result/100); > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator