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] ...
随机推荐
- AJAX JSON类型返回
文本样式和下拉样式 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- settimeout,cleartimeout的使用分析
设置时间的定时轮回执行,大家想到的js也就是settimeout这个方法,这个方法确实能够实现定时反复执行的功能,clearttimeout这是清理或者是暂停轮回执行的情况.可是发现clearttim ...
- <jsp:include>和<%@include file=""%>区别【131031】
<jsp:include page=""> 父页面和包含进来的页面单独编译,单独翻译成servlet后,在前台拼成一个HTML页面. <%@include fil ...
- Linux中exec()执行文件系列函数的使用说明
函数原型: 描述: exec()系列函数使用新的进程映像替换当前进程映像. 工作方式没有什么差别, 只是参数传递的方式不同罢了. 说明: 1. 这6个函数可分为两大类: execl( ...
- HDU2296 Ring(AC自动机 DP)
dp[i][j]表示行走i步到达j的最大值,dps[i][j]表示对应的串 状态转移方程如下: dp[i][chi[j][k]] = min(dp[i - 1][j] + sum[chi[j][k]] ...
- Zigzag
date: 2015-09-24 21:09:00 Print Zigzag 思路: 1 首先是按行输出,每行输出相同位置的下一间隔为row*2-2,行游标0 初始化时(每一行的首个斜向部分),j=i ...
- 字符串截取函数--C语言(转)
#include<stdio.h> #include<stdlib.h> char* substring(char* ch,int pos,int length) { char ...
- POJ 1741 Tree 树分治
Tree Description Give a tree with n vertices,each edge has a length(positive integer less than 1 ...
- Vue#计算属性
在模板中表达式非常便利,但是它们实际上只用于简单的操作.模板是为了描述视图的结构.在模板中放入太多的逻辑会让模板过重且难以维护.这就是为什么 Vue.js 将绑定表达式限制为一个表达式.如果需要多于一 ...
- 【POI word】使用POI实现对Word的读取以及生成
项目结构如下: 那第一部分:先是读取Word文档 package com.it.WordTest; import java.io.FileInputStream; import java.io.Fil ...