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";
}
};
topcoder SRM 623 DIV2 CatchTheBeatEasy的更多相关文章
- topcoder SRM 623 DIV2 CatAndRat
解决本题的一个关键点就是当Cat进入时,此时Rat在哪个位置? 注意移动方向可以随时改变,由于是圆环,故离入口最远点的距离是pi*R,即圆的一半, 当cat进入时(cat的速度大于rat的速度,否则不 ...
- Topcoder Srm 673 Div2 1000 BearPermutations2
\(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...
- Topcoder Srm 671 Div2 1000 BearDestroysDiv2
\(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...
- 求拓扑排序的数量,例题 topcoder srm 654 div2 500
周赛时遇到的一道比较有意思的题目: Problem Statement There are N rooms in Maki's new house. The rooms are number ...
- Topcoder srm 632 div2
脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...
- topcoder SRM 628 DIV2 BracketExpressions
先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配 #include <vector> #include <string> #include <list> # ...
- topcoder SRM 628 DIV2 BishopMove
题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is ...
- Topcoder SRM 683 Div2 B
贪心的题,从左向右推过去即可 #include <vector> #include <list> #include <map> #include <set&g ...
- Topcoder SRM 683 Div2 - C
树形Dp的题,根据题意建树. DP[i][0] 表示以i为根节点的树的包含i的时候的所有状态点数的总和 Dp[i][1] 表示包含i结点的状态数目 对于一个子节点v Dp[i][0] = (Dp[v] ...
随机推荐
- EasyUi–8.datebox赋值的问题
这个问题要从EasyUI的datebox组件说起,小菜用这个组件的时候,发现用$("#id").val()这种形式,居然拿不到文本框的值! 经过度娘的帮助,发现可以用$( ...
- Gmail 账号找回办法
前段时间一直在用GFW代理,结果发现GOOGLE账户的保护机制起用了,要给以前的手机号发消息,结果哪个号现在不用了,所以就登陆不进去了,非常扯淡,索性谷歌了下,得出如下的解决方案,完美解决,下次直接在 ...
- 【20140113】package 与 import
一个完整的java源程序应该包括下列部分: package语句: //该部分至多只有一句,必须放在源程序的第一句 import语句: public classDefinition: //公共类定义部分 ...
- 在ASP.NET Core 1.0中如何发送邮件
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:目前.NET Core 1.0中并没有提供SMTP相关的类库,那么要如何从ASP.NE ...
- 使用VS把ASP.NET 5的应用发布到Linux的Docker上
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:我相信未来应用程序的部署模式首选一定会是Docker,所以.NET社区的朋友也不应该忽 ...
- 全零网络IP地址0.0.0.0表示意义详谈
转自:http://liuzhigong.blog.163.com/blog/static/17827237520114207278610/ RFC: 0.0.0.0/8 - Addresses in ...
- 单例模式/singleton模式/创建型模式
Java实现要点: 私有构造方法 线程安全(并发的考虑) 延迟加载(效率的考虑,对于较大的类在使用时在加载) 公有方法访问单一实例 常见单例模式代码及问题 //无延迟加载,常驻内存(即使不使用) cl ...
- sublime text 2中Emmet8个常用的技巧
原文链接:http://blog.csdn.net/lmmilove/article/details/9181323 因为开始做web项目,所以最近在用sublime编辑器,知道了一个传说中的emme ...
- 使用lsof查看进程句柄使用情况
lsof -n |awk '{print $2}'|sort|uniq -c |sort -nr|more
- KMP算法代码
以下是本人根据上一篇博客随笔http://www.cnblogs.com/jiayouwyhit/p/3251832.html,所写的KMP算法代码(暂未优化),个人认为在基于上一篇博客的基础上,代码 ...