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 ...
随机推荐
- BZOJ1911:[Apio2010]特别行动队——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1911 又是一个显然的dp……好吧我懒得讲了. s[i]是战斗力前缀和. 我们仍然设k<j< ...
- BZOJ3076 & 洛谷3081:[USACO2013 MAR]Hill Walk 山走——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=3076 https://www.luogu.org/problemnew/show/P3081#sub ...
- 洛谷3794:签到题IV——题解
https://www.luogu.org/problemnew/show/P3794 题目见上. 有一个套路(虽然我到现在还不会),就是固定一个端点,二分查右端点. 显然这题的正解是O(nlogn) ...
- bzoj1051: [HAOI2006]受欢迎的牛(tarjan强连通分量)
强连通缩下点,出度为0有多个答案为0,否则答案为出度为0的强连通分量中点的个数. 发现一道tarjan模板题,顺便复习一波tarjan #include<iostream> #includ ...
- linux上修改系统默认语言设置
locale命令设置语言环境(临时修改) [keysystem@localhost ~]$ date Fri Feb :: CST [keysystem@localhost ~]$ locale LA ...
- ACE线程管理机制-线程的创建与管理
转载于:http://www.cnblogs.com/TianFang/archive/2006/12/04/581369.html 有过在不同的操作系统下用c++进行过多线程编程的朋友对那些线程处理 ...
- BZOJ1880: [Sdoi2009]Elaxia的路线(最短路)
1880: [Sdoi2009]Elaxia的路线 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 2049 Solved: 805 题目链接:https ...
- MongoDB入门(8)- c#通过操作MongoDB GridFS实现文件的数据库存储
GridFS介绍 GridFS是MongoDB中的一个内置功能,可以用于存放大量小文件. GridFS GridFS长啥样 /* 1 */ { "_id" : ObjectId(& ...
- 数据结构&图论:图
在这里对图的存储和遍历进行一个规范,为以后更复杂的数据结构学习打下基础 首先是邻接矩阵的形式,适合于存稠密图,如果是全连接图就再合适不过了 int a[maxn][maxn]; 一个二维数组就可以搞定 ...
- 2015/9/19 Python基础(15):变量作用域及生成器
变量作用域标识符的作用域是定义为其声明的可应用范围,或者即是我们所说的变量可见性.也就是,我们可以在程序的那个部分去访问一个制定的标识符.全局变量与局部变量定义在函数内的变量有局部作用域,在一个模块中 ...