• CodeForces 730G Car Repair Shop (暴力)


    题意:给定 n 个工作的最好开始时间,和持续时间,现在有两种方法,第一种,如果当前的工作能够恰好在最好时间开始,那么就开始,第二种,如果不能,那么就从前找最小的时间点,来完成。

    析:直接暴力,每次都先去看看能不能在最好时间完成,如果不能,就去找最小的时间点。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const LL LNF = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e2 + 100;
    const int mod = 1e9 + 7;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline int Min(int a, int b){ return a < b ? a : b; }
    inline int Max(int a, int b){ return a > b ? a : b; }
    inline LL Min(LL a, LL b){ return a < b ? a : b; }
    inline LL Max(LL a, LL b){ return a > b ? a : b; }
    inline int gcd(int a, int b){ return b ? gcd(b, a%b) : a; }
    inline int lcm(int a, int b){ return a * b / gcd(a, b); }
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    struct Node{
        int l, r;
        Node() { }
        Node(int ll, int rr) : l(ll), r(rr) { }
        bool operator < (const Node &p) const{
            return l < p.l;
        }
    };
    Node a[205];
    
    int main(){
        while(scanf("%d", &n) == 1){
            int s, d;
            int cnt = 1;
            a[0] = Node(0, 0);
            cin >> s >> d;
            printf("%d %d
    ", s, s+d-1);
            a[cnt++] = Node(s, s+d-1);
            for(int i = 1; i < n; ++i){
                cin >> s >> d;
                --d;
                sort(a, a+cnt);
                if(a[cnt-1].r < s){
                    printf("%d %d
    ", s, s+d);
                    a[cnt++] = Node(s, s+d);
                    continue;
                }
    
                bool ok = false;
                for(int j = 0; j < cnt-1; ++j){
                    if(s > a[j].r && s+d < a[j+1].l){
                        ok = true;
                        printf("%d %d
    ", s, s+d);
                        a[cnt++] = Node(s, s+d);
                        break;
                    }
                }
                if(!ok){
                    bool ok1 = false;
                    for(int j = 1; j < cnt; ++j){
                        if(a[j].l - a[j-1].r > d+1){
                            printf("%d %d
    ", a[j-1].r+1, a[j-1].r+d+1);
                            a[cnt++] = Node(a[j-1].r+1, a[j-1].r+d+1);
                            ok1 = true;
                            break;
                        }
                    }
                    if(!ok1){
                        printf("%d %d
    ", a[cnt-1].r+1, a[cnt-1].r+1+d);
                        a[cnt] = Node(a[cnt-1].r+1, a[cnt-1].r+d+1);
                        ++cnt;
                    }
                }
    
            }
        }
        return 0;
    }
    
  • 相关阅读:
    20162325 金立清 S2 W7 C16
    2017-2018-1 我爱学Java 第三周 作业
    Android演示Stack(课下作业)
    20162325 金立清 S2 W6 C15
    YanghuiTriangle
    20162327WJH第一次实验——线性结构
    20162327 《程序设计与数据结构》第三周学习总结
    20162327《程序设计与数据结构》第一周作业
    20162327WJH 实验三 《敏捷开发与XP实践》 实验报告
    20162328WJH实验五网络编程与安全实验报告
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5997956.html
Copyright © 2020-2023  润新知