zoukankan      html  css  js  c++  java
  • 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];
    	}
    };
    
  • 相关阅读:
    newCachedThreadPool无上限线程池使用
    newFixedThreadPool固定线程使用
    java定时器
    http文件上传/下载
    ThreadPoolExecutor线程池
    阻塞队列
    非阻塞队列
    IO文件夹拷贝(文件内含有文件和文件夹)
    MD5加密
    web.xml文件的作用
  • 原文地址:https://www.cnblogs.com/qdscwyy/p/9770434.html
Copyright © 2011-2022 走看看