【CodeForces】[629B]Far Relative’s Problem

这里写图片描述

一直感觉这种题目不算贪心
但是却又看到好多把它分类到贪心
应该也是有关于区间贪心的写法
然而一直没想到也没找到相关写法
这个复杂度取决于区间大小
贪心策略取决于n的大小
应该也是可以有所抉择

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct node {
    char sex;
    int l,r;
} a[5200];
int man[5200],woman[5200];
int main() {
    int n;
    while(scanf("%d",&n)!=EOF) {
        getchar();
        memset(man,0,sizeof(man));
        memset(woman,0,sizeof(woman));
        for(int i=0; i<n; i++) {
            scanf("%c %d %d",&a[i].sex,&a[i].l,&a[i].r);
            getchar();
            if(a[i].sex=='M') {
                for(int j=a[i].l; j<=a[i].r; j++)
                    man[j]++;
            } else {
                for(int j=a[i].l; j<=a[i].r; j++)
                    woman[j]++;
            }
        }
        int res=0;
        for(int i=1; i<367; i++) {
            res=max(res,min(man[i],woman[i]));
        }
        printf("%d
",res*2);
    }
    return 0;
}

题目地址:【CodeForces】[629B]Far Relative’s Problem

原文地址:https://www.cnblogs.com/BoilTask/p/12569494.html