topcoder SRM 623 DIV2 CatchTheBeatEasy
2024-10-19 07:33:54
比较简单的一题,纠结比较久的是把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";
}
};
最新文章
- JS对象深刻理解 - 2
- Android项目实战(六):JazzyGridView和JazzyListView的使用
- Hadoop 数据库 - HBase
- S2小测--索引--视图
- 像jQuery那样,采用链式方法,封装一个方法:CSS()
- sql拼接字符串和转换类型
- STORM_0005_第一个非常简单的storm topology的提交运行
- Java中Integer的源码学习
- MySQL删除外键定义的方法
- No suitable authentication method found to complete authentication (publickey,keyboard-interactive).
- jQuery自学笔记(四):jQuery DOM节点操作
- C语言基础学习基本数据类型-变量的输出与输入
- ios 自己定义导航栏和切割线
- MUI判断网络连接以及监听网络变化JS
- SQL Server 连接 MySQL
- 使用ML.NET实现NBA得分预测
- [luogu1962]斐波那契数列
- 三种方法获取Class对象的区别
- day25
- 【bzoj1089】严格n元树