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 |
哪位大哥大姐帮我看看哪里错了,总是WA#include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; class XY { public: XY(double x, double y) : _x(x), _y(y){} double _x; double _y; }; class Range { public: Range(double x1, double x, double x2) : _x1(x1), _x2(x2), _x(x){} double _x1; double _x2; double _x; bool Intersection(const Range& rhs) { if(_x >= rhs._x1 || fabs(_x - rhs._x1) < 1e-6) { if(_x <= rhs._x2 || fabs(_x - rhs._x2) < 1e-6) { return true; } } return false; } double GetRange() const { return _x2 - _x1; } }; class Functor { public: bool operator()(const Range& lhs, const Range& rhs) { return (lhs.GetRange() < rhs.GetRange()); } }; int GetRadarNum(vector<Range>& vecRange) { int ret = 0; int* pInt = new int[vecRange.size()]; for(int i = 0; i < vecRange.size(); ++i) { pInt[i] = 1; } for(int i = 0; i < vecRange.size(); ++i) { if(1 == pInt[i]) { ++ret; pInt[i] = 0; for(int j = 0; j < vecRange.size(); ++j) { if(1 == pInt[j] && vecRange[i].Intersection(vecRange[j])) { pInt[j] = 0; } } } } delete[] pInt; return ret; } int Greedy(int n, int d, vector<XY>& vecXY) { int ret = 0; if(n < 1 || d <= 0) { return -1; } vector<Range> vecRange; for(vector<XY>::iterator iter = vecXY.begin(); iter != vecXY.end(); ++iter) { if(iter->_y > d) return -1; Range range(iter->_x - sqrt((double)d * d - iter->_y * iter->_y), iter->_x, iter->_x + sqrt((double)d * d - iter->_y * iter->_y)); vecRange.push_back(range); } Functor functor; sort(vecRange.begin(), vecRange.end(), functor); ret = GetRadarNum(vecRange); if(0 == ret) return -1; return ret; } int main() { int n = 0; int d = 0; int x = 0; int y = 0; int caseNo = 1; while(cin >> n >> d) { if(n == 0 && d == 0) { break; } vector<XY> vecXY; for(int i = 0; i < n; ++i) { cin >> x >> y; XY xy(x, y); vecXY.push_back(xy); } cout << "Case " << caseNo << ": " << Greedy(n, d, vecXY) << endl; ++caseNo; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator