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:哪位大神,给小弟一些错误的测试数据,不胜感激,总是runtime ErrorIn Reply To:哪位大神,给小弟一些错误的测试数据,不胜感激,总是runtime Error Posted by:dreamvyps at 2010-08-23 14:38:19 > #include <iostream> > #include <string> > #include <cstdlib> > #include <cmath> > #include <algorithm> > using namespace std; > struct range > { > double start; > double end; > }; > > range rang_t[1000]; > > bool cmp(const range& a,const range& b) > { > return a.start > b.start; > }; > int main() > { > > int n = 0,d = 0; > int x = 0,y = 0; > int num = 1; > for (;cin >> n >> d;++num) > { > if (n == 0) > { > break; > } > if (n == 1) > { > cin >> x >> y; > if (y > d || d <= 0 || y < 0) > { > cout << "Case " << num <<": " << "-1" << endl; > } > else > cout << "Case " << num <<": " << "1" << endl; > continue; > } > for (int i = 1; i <= n;++i) > { > cin >> x >> y; > rang_t[i].start = x - sqrt((double)(d*d - y*y)); > rang_t[i].end = x + sqrt((double)(d*d - y*y)); > } > > > > sort(rang_t,rang_t+n,cmp); > int counter = 1; > int cur = rang_t[1].end; > for (int i = 2; i <= n; ++i) > { > if (cur < rang_t[i].start) > { > counter++; > cur = rang_t[i].end; > } > if (cur > rang_t[i].end) > { > cur = rang_t[i].end; > } > } > cout << "Case " << num <<": " << counter << endl; > > > } > return 0; > } 貌似里面的cmp写错了,应该是从小到大排序。 且sort写错了。应该是sort(rang_t+1,rang_t+1+n,cmp); 请大牛指教!!! Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator