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 ...
随机推荐
- apache和IIS共享80端口解决办法
第一步:把iis所发布的网站默认端口由80改为8080:第二步:修改apache的httpd.conf配置文件. 首先,要让apache支持转发也就是做iis的代理那么就要先启 用apache的代理模 ...
- Hadoop及Zookeeper+HBase完全分布式集群部署
Hadoop及HBase集群部署 一. 集群环境 系统版本 虚拟机:内存 16G CPU 双核心 系统: CentOS-7 64位 系统下载地址: http://124.202.164.6/files ...
- Codeforces Round #547 (Div. 3) 题解
Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...
- java RSA加密解密实现(含分段加密)
该工具类中用到了BASE64,需要借助第三方类库:javabase64-1.3.1.jar 下载地址:http://download.csdn.net/detail/centralperk/50255 ...
- HDU 5901 Count primes 大素数计数
题意:计算1~N间素数的个数(N<=1e11) 题解:题目要求很简单,作为论文题,模板有两种 \(O(n^\frac{3}{4} )\),另一种lehmer\(O(n^\frac{2}{3})\ ...
- 51nod 1170 1770 数数字(数学技巧)
解题思路:看到题后,直接想到分成两种情况: ①:a*b >9 这里又分成两种 1. n==1 a*b 直接是一个两位数 求得十位和个位(这里十位和个位不可能相等) 然后如果等于d 则结果=1 2 ...
- 解决方案:WindowsError: [Error 2]
使用Python的rename()函数重命名文件时出现问题,提示 WindowsError: [Error 2] 错误,最初代码如下: def renameFile(filename): filePr ...
- 【uva12232/hdu3461】带权并查集维护异或值
题意: 对于n个数a[0]~a[n-1],但你不知道它们的值,通过逐步提供给你的信息,你的任务是根据这些信息回答问题: I P V :告诉你a[P] = V I P Q V:告诉你a[P] XOR a ...
- 【BZOJ1221】【HNOI2001】软件开发 [费用流]
软件开发 Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 某软件公司正在规划一项n天的软件开 ...
- 【BZOJ2693】jzptab [莫比乌斯反演]
jzptab Time Limit: 10 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description 求 Input 第一行一个 ...