zoukankan      html  css  js  c++  java
  • 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 = 0 ; 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 = 0;
        for(int i = 0 ; 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";
    }
    };
  • 相关阅读:
    第一周作业
    C语言I博客作业08
    十四周助教总结
    十三周助教总结
    C语言I博客作业07
    C语言II博客作业01
    学期总结
    C语言I博客作业08(未完成)
    C语言I博客作业07
    C语言I博客作业06
  • 原文地址:https://www.cnblogs.com/xiongqiangcs/p/3771106.html
Copyright © 2011-2022 走看看