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 |
测试其他数据都对 就0.04错 谁能帮忙看下#include <iostream> using namespace std; const double delta=1e-8; //精度范围 int zero(double x) { if(x>delta) return 1; if(x<-delta) return -1; else return 0; } int main() { int total,i; double len[1000]={0}; for(total=1;zero(len[total-1]-5.20)<0;total++) //建一离线表,len[i]表示前i张卡片一共伸出的长度和 len[total]=len[total-1]+(double)(1.0/(total+1)); int left,right,mid; double x; cin>>x; while(zero(x)) //用二分法在离线表中检索 { left=1; right=total; while(left+1<right) { mid=(left+right)/2; if(zero(len[mid]-x)<0) { left=mid; } else { right=mid; } } cout<<right<<" card(s)"<<endl; cin>>x; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator