hdu1050(贪心)

囧 。 想了好久,一开始想的是一个连通图怎样用黑白两色染色,想了各种算法发现都不好做,然后灵机一动这不是网路流吗,然后想怎么建图,如果转换成网络流这题就好做了,建图加个二分应该就可以解决了,最后又发现好像只要找出哪段走廊被用过得次数最多就行了。。。 这么简单的题却想了这么久。 不过用了网络流的方法想这题的这种贪心就好解释了。

hdu 1050

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;

int sum[222];


int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        memset(sum,0,sizeof(sum));
        for(int i=1;i<=n;i++)
        {
            int b,d;
            scanf("%d%d",&b,&d);
            if(b>d) swap(b,d);
            for(int i=(b%2==0?b:b+1);i<=(d%2==0?d:d+1);i+=2)
            {
                sum[i/2]++;
            }
        }
        int ans=0;
        for(int i=1;i<=200;i++)
            ans=max(ans,sum[i]);
        printf("%d
",ans*10);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/chenhuan001/p/4062221.html