topcoder SRM 623 DIV2 CatchTheBeatEasy

比较简单的一题,纠结比较久的是把my_cmp和my_minus放在类中,利用sort函数会出现

no matching function for call to ""sort(std::vector<Interval>::iterator, std::vector<Interval>::iterator, <unresolved overloaded function type>)""

当把这两个函数放在类外面时就行了
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std; typedef pair<int,int> Point;
bool my_cmp(const Point& a, const Point& b){
return a.second < b.second;
} Point my_minus( Point&a, Point& b){
return Point(a.first,a.second-b.second);
} class CatchTheBeatEasy{
public:
string ableToCatchAll(vector<int> x, vector<int> y){
vector<Point> points;
for(int i = ; i < x.size(); ++ i)
points.push_back(make_pair(x[i],y[i]));
sort(points.begin(),points.end(),my_cmp);
adjacent_difference(points.begin(),points.end(),points.begin(),my_minus);
int start = ;
for(int i = ; i< points.size(); ++i){
if(abs(points[i].first-start) > points[i].second) return "Not able to catch";
start = points[i].first;
}
return "Able to catch";
}
};
上一篇:Selenium-java-testng插件安装eclipse


下一篇:NGUI 多场景情况下 管理多个界面