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 ...
随机推荐
- NVIDIA TensorRT 让您的人工智能更快!
NVIDIA TensorRT 让您的人工智能更快! 英伟达TensorRT™是一种高性能深度学习推理优化器和运行时提供低延迟和高通量的深度学习推理的应用程序.使用TensorRT,您可以优化神经网络 ...
- selenium-控制浏览器操作
from selenium import webdriver driver = webdriver.Chrome() #打开浏览器 driver.get(urlname) #控制浏览器窗口大小 dri ...
- ps命令查看进程指定项目信息、用户名过长显示UID
有次一个在使用ps命令时,发现部分用户显示的是用户名,有些用户显示的是UID,那是因为用户名长度超过8位的:也就是说ps命令用户名列默认只能显示8位(含8位)的用户名,超过8位就显示UID,如何让长度 ...
- centOS升级部分功能后,不能进入桌面(桌面)
在Linux中安装nginx,安装过程中需要安装c++等一部分环境,装完后,莫名奇妙的centos就不能进入桌面了,命令窗口可以进去. 网上查了查资料,说是升级了一部分功能,和内核有冲突.需要更新下系 ...
- C语言数组与指针总结
寒假要开始猛刷<剑指offer>,先回顾一下C语言基础做个热身. 指针 相信大家对下面的代码不陌生: ; int *p; p=&i; 这是最简单的指针应用,也是最基本的用法.再来熟 ...
- springboot-用logback将日志文件按等级保存到不同文件
springboot-用logback将日志文件按等级保存到不同文件 案例: 例如项目基本包名为com.xxx,将该包下的所有日志按debug.info.warn.error等级分别保存到D:/log ...
- Android SearchView结合Filter实现列表检索功能使用总结
下面贴出主要代码: <span style="font-size:14px;"> public class MainActivity ex ...
- angularJs $resource自定义方法(待完善)
配置CompanyService var services = angular.module('liaoyuan.services'); services.factory('CompanyServic ...
- 51Nod 最大子矩阵和 | DP
Input 第1行:M和N,中间用空格隔开(2 <= M,N <= 500). 第2 - N + 1行:矩阵中的元素,每行M个数,中间用空格隔开.(-10^9 <= M[i] < ...
- 状压DP的总结
状压dp的标志 ①数据小 ②通过题目所给出的条件以后得到的特征集合小 一:CF259div2 D: 题目大意:保证b[i]中每个数互质,给出a[i],然后求1~n的abs(a[i]-b[i])最小.a ...