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 ... 
随机推荐
- C++ 类中成员函数分析
			概述之前对成员变量的分布进行了整理,今天就对成员函数进行整理. 1.非静态成员函数C++的设计准则之一就是:非静态成员函数至少和一般的非成员函数的执行效率相同. 为了实现上衣准则,编译器会对非静态成员 ... 
- POJ3347:Kadj Squares——题解
			http://poj.org/problem?id=3347 题目大意:给定一些正方形的边长,让他们尽可能向左以45°角排列(不能互相重合),求在上面看只能看到哪几个正方形. ———————————— ... 
- 【Codeforces 506E】Mr.Kitayuta’s Gift&&【BZOJ 4214】黄昏下的礼物 dp转有限状态自动机+矩阵乘法优化
			神题……胡乱讲述一下思维过程……首先,读懂题.然后,转化问题为构造一个长度为|T|+n的字符串,使其内含有T这个子序列.之后,想到一个简单的dp.由于是回文串,我们就增量构造半个回文串,设f(i,j, ... 
- ipython 安装和更新
			pip install ipython pip install --upgrade ipython pip install --upgrade pip 不管是用pip装什么模块,前面都尽量不要加sud ... 
- spring cloud  config的bootstrap.yml与application.proterties的区别
			bootstrap.yml 和application.yml 都可以用来配置参数 bootstrap.yml可以理解成系统级别的一些参数配置,这些参数一般是不会变动的 application.ym ... 
- MFC:CTime类和CTimeSpan类
			CTime类 CTime类表示日期和时间,上限是3000年12月31日,下限是1970年1月1日 12:00:00 AM GMT. CTime(); 构造一个未经初始化的CTime对象.此状态的CTi ... 
- POJ 2391 二分+最大流
			Ombrophobic Bovines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19066 Accepted: 4 ... 
- 使用 log4j 在控制台 打印 hibernate 语句参数
			log4j.rootLogger=INFO, stdoutlog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.st ... 
- 【设计模式】 模式PK:策略模式VS状态模式
			1.概述 行为类设计模式中,状态模式和策略模式是亲兄弟,两者非常相似,我们先看看两者的通用类图,把两者放在一起比较一下. 策略模式(左)和状态模式(右)的通用类图. 两个类图非常相似,都是通过Cont ... 
- MySQL 基于 GTID 主从架构添加新 Slave 的过程
			内容全部来自: How to create/restore a slave using GTID replication in MySQL 5.6 需求说明 需求: 对于已经存在的 MySQL 主从架 ... 
