• 【HDOJ】2037 今年暑假不AC


    qsort排序后DP,水题。注意,数组开大点儿,把时间理解为0~23,开太小会wa。

    #include <stdio.h>
    #include <stdlib.h>
    
    #define MAXNUM 100
    
    int comp(const void *a, const void *b) {
        return *(int *)a - *(int *)b;
    }
    
    int mymax(int a, int b) {
        return (a>b) ? a:b;
    }
    
    int main() {
        int time[MAXNUM][2], n;
        int i, j, end;
        int num[MAXNUM];
    
        while (scanf("%d", &n) != EOF && n) {
            end = 0;
            for (i=0; i<n; ++i) {
                scanf("%d %d", &time[i][0], &time[i][1]);
                if (time[i][1] > end)
                    end = time[i][1];
            }
    
            qsort(time, n, sizeof(int)*2, comp);
            memset(num, 0, sizeof(num));
    
            for (i=0; i<n; ++i) {
                if (num[time[i][0]]+1 > num[time[i][1]]) {
                    num[time[i][1]] = num[time[i][0]]+1;
                    for (j=time[i][1]; j<=end; ++j) {
                        num[j] = mymax(num[j], num[time[i][1]]);
                    }
                }
            }
    
            printf("%d
    ", num[end]);
        }
    
    
        return 0;
    }
  • 相关阅读:
    2019年11月28日开发手记
    2019年11月26日开发手记
    2019年11月25日开发手记
    2019年11月24日开发手记
    2019年11月23日开发手记
    R学习
    python学习目录
    自动化测试appium
    python爬虫的进阶用法
    asyncio
  • 原文地址:https://www.cnblogs.com/bombe1013/p/3575811.html
Copyright © 2020-2023  润新知