SRM 739 Div.2
250
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct Pair {
int val, p;
Pair() {
}
Pair(int _, int __) {
val = _, p = __;
}
bool operator < (Pair o) const {
return val < o.val;
}
};
class HungryCowsEasy {
public:
vector<int> findFood(vector<int> A, vector<int> C) {
vector<int> Res;
vector<Pair> B;
for (int i = 0; i < C.size(); i += 1) {
B.push_back(Pair(C[i], i));
}
stable_sort(B.begin(), B.end());
for (int i = 0; i < A.size(); i += 1) {
int p = lower_bound(B.begin(), B.end(), Pair(A[i], 0)) - B.begin();
if (p < 0) Res.push_back(0);
else if (p > 0 and abs(A[i] - B[p - 1].val) <= abs(A[i] - B[p].val))
Res.push_back(B[p - 1].p);
else if (p < B.size() - 1 and abs(B[p + 1].val - A[i]) < abs(A[i] - B[p].val))
Res.push_back(B[p + 1].p);
else Res.push_back(B[p].p);
}
return Res;
}
};
第二题
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
class ForumPostMedium{
public:
string ans[3];
ForumPostMedium() {
ans[0] = "few seconds ago";
ans[1] = " minutes ago";
ans[2] = " hours ago";
}
int getid(char a,char b) {
return (a - '0') * 10 + (b - '0');
}
string getShownPostTime(string t, string s) {
int a[5], b[5];
a[1] = getid(s[0], s[1]); a[2] = getid(s[3], s[4]); a[3] = getid(s[6], s[7]);
b[1] = getid(t[0], t[1]); b[2] = getid(t[3], t[4]); b[3] = getid(t[6], t[7]);
LL l = a[1] * 3600 + a[2] * 60 + a[3];
LL r = b[1] * 3600 + b[2] * 60 + b[3];
LL x = r - l;
if (x < 0) x += 86400;
if (x < 60) return ans[0];
else if (x < 3600) return ttoo(x / 60) + ans[1];
else return to_string(x / 3600) + ans[2];
}
};
SRM 739 Div.2的更多相关文章
- Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1
据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...
- TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E
传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...
- 竞赛图的得分序列 (SRM 717 div 1 250)
SRM 717 DIV 1 中 出了这样一道题: 竞赛图就是把一个无向完全图的边定向后得到的有向图,得分序列就是每个点的出度构成的序列. 给出一个合法的竞赛图出度序列, 要求构造出原图(原题是求(u, ...
- TopCoder SRM 667 Div.2题解
概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...
- 刷题记录:Codeforces Round #739 (Div. 3)
Codeforces Round #739 (Div. 3) 20210907.网址:https://codeforces.com/contest/1560. --(叹). A 不希望出现带" ...
- Topcoder SRM 648 (div.2)
第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...
- SRM 638 Div.2
250 给一个字符串 要求从一种形式换成另一形式 class NamingConvention{ private: int a, b, c; public: int d; string toCamel ...
- [topcoder]SRM 646 DIV 2
第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...
- [topcoder]SRM 633 DIV 2
第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...
随机推荐
- ACM1325Is it A tree?
通过这道简单而又坑人的题目,练习并查集和set 容器的使用: Is It A Tree? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- zigbee ---- 各种ID的作用
EPAN ID的作用:
- Eclipse debug模式下使用16进制(Hex)查看变量值
转载自:http://blog.csdn.net/jinhill/article/details/5767035 因为工作中需要查看byte[]原始编码,eclipse中debug模式下默认查看byt ...
- Tomcat 映射虚拟目录和程序热部署
虚拟目录的设置 方法一:在${tomcat安装目录}/conf/Catalina/localhost目录下创建一个xml文件,任意文件名都可以,但是此文件名是web应用发布后的虚拟目录: 比如创建一个 ...
- SourceTree for mac 注册过程(v2.7.6a)
背景 为啥要自己注册呢,往上一堆一堆的老版本许可证偏不用,就愿意定制自己的账号style. 搞了半天,还是觉得pycharm自带的git工具就挺好用了,闲的没事记录一下. 要点 百度搜索的地址可以进入 ...
- 使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,报异常的解决方法
使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,会报异常. 例如: <select id="getPersonRecordId" parameterTy ...
- Python编写在Maya中查看文件列表的插件
之前写过一篇用Python遍历文件夹的文章,今天把代码扩展一下,做成一个有UI用户界面的Maya插件,可以直接在Maya中运行: 功能是显示磁盘分区目录下的文件列表,通过定制也可以查看任意目录下的文件 ...
- MVP应用在android app上
使用MVP模式来解耦activity中业务代码和界面代码.在activity中,将其中的业务抽象到presenter层:将其中的界面代码抽象到View层. MVP模式: 一个软件被划分成三层,View ...
- Bzoj2832 / Bzoj3874 宅男小C
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 124 Solved: 26 Description 众所周知,小C是个宅男,所以他的每天的食物要靠外 ...
- Achain 钱包部署
官网 GIT: [ Achain_linux ] 基础环境 OS: CentOS, Ubuntu Achain: 官网 [ release 最新版本 ] 安装 Achain 钱包 下载 CentOS ...