• CF767 B. The Queue 贪心+细节


    LINK

    题意:一个业务开始时间为s,结束时间为f,一个人办护照的时间需要m分(如果在x时开始服务,且x+m==f那么还是合法的),你可以选择任意时间到达,但如果你和其他人同时到达,你要排在他的后面。问什么时候去等待时间最小。

    思路:贪心,对所有人枚举在他之前1分钟到达和同时到达的情况。 因为对于任意一个人,在他1分前到达时,能够保证必定先于该人服务,且等待前一个人服务时间最小,而同时到达时能保证必定比后面的人先服务。 不断更新开始的时间为前一个人结束服务时间,并更新最小等待时间。 要注意特殊情况,如果有人0时到达,那么不可能比他先到了。

    /** @Date    : 2017-04-17 20:26:35
      * @FileName: 767B greed.cpp
      * @Platform: Windows
      * @Author  : Lweleth (SoundEarlf@gmail.com)
      * @Link    : https://github.com/Lweleth
      * @Version : $Id$
      */
    #include <bits/stdc++.h>
    #define LL long long
    #define PII pair
    #define MP(x, y) make_pair((x),(y))
    #define fi first
    #define se second
    #define PB(x) push_back((x))
    #define MMG(x) memset((x), -1,sizeof(x))
    #define MMF(x) memset((x),0,sizeof(x))
    #define MMI(x) memset((x), INF, sizeof(x))
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    const int N = 1e5+20;
    const double eps = 1e-8;
    
    LL a[N];
    int main()
    {
    	LL s, f, m;
    	int n ;
    	while(cin >> s >> f >> m)
    	{
    		cin >> n;
    		for(int i = 0; i < n; i++)
    			scanf("%lld", a + i);
    
    		LL ls = 1e15+10;
    		LL mi = 1e15+10;
    		for(int i = 0; i < n; i++)
    		{
    			int ma = max(a[i] - 1, s);
    			if(a[i] == 0 || a[i] + m > f)
    				continue;
    			if(ma + m <= f && s - (a[i] - 1) <= ls)
    			{
    				ls = s - (a[i] - 1);
    				mi = min(a[i] - 1, s);
    			}
    			s = max(s, a[i]) + m;
    		}
    		if(s + m <= f)
    			mi = s;
    		printf("%lld
    ", mi);
    	}
        return 0;
    }
    
  • 相关阅读:
    docker compose 笔记
    一个简单的计划
    译Node.js应用的持续部署
    Javascript中的字典和散列
    施耐德保护调试技巧
    施耐德Sepam 40系列备自投逻辑
    请随时告诉自己
    顺其自然
    启用
    我们能做的是......
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/6735058.html
Copyright © 2020-2023  润新知