hdu 3729

去年天津赛的题目,重新看了一下题,如果今年去那场比赛,估计能A5道左右吧

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct node
{
    int val, id;
}t[200];
int mat[61][4000];
bool used[4000];
int links[4000];
int to[61];
int g[61][2];
int gx, gy;
bool cmp(node a, node b)
{
    return a.val < b.val;
}
bool can(int t)
{
    for(int i  = 1; i <= gy; i++)
    {
        if(!used[i] && mat[t][i])
        {
            used[i] = 1;
            if(links[i] == -1 || can(links[i]))
            {
                links[i] = t;
                to[t]  = i;
                return true;
            }
        }
    }
    return false;
}
void MaxMatch()
{
    int num = 0;
    memset(links, -1, sizeof(links));
    memset(to, -1, sizeof(to));
    for(int i = gx; i >= 1; i--)
    {
        memset(used, 0, sizeof(used));
        if(can(i))  num++;
    }
    printf("%d\n", num);
    bool flag = false;
    for(int i = 1; i <= gx; i++)
    {
        if(to[i]!=-1)
        {
            if(!flag)
            {
                printf("%d",i);
                flag=true;
            }
            else
            {
                printf(" %d", i);
            }
        }
    }
    printf("\n");
}
int main()
{
    int T;
    int x, y;
    scanf("%d", &T);
    while(T--)
    {
        int n;
        int num = 0;
        scanf("%d", &n);
        for(int i = 1; i <= n; i++)
        {
            scanf("%d%d", &x, &y);
            t[num].id = i;
            t[num++].val = x;
            t[num].id = - i;
            t[num++].val = y;
        }


        sort(t, t + num, cmp);
        int cou = 1;
        if(t[0].id > 0)
        {
            g[t[0].id][0]  = 1;
        }
        else
        {
            g[-t[0].id][1] = 1;
        }
        for(int i = 1; i < num; i++)
        {
            if(t[i].val == t[i-1].val)
            {
                if(t[i].id > 0)  g[t[i].id][0] = cou;
                else g[-t[i].id][1] = cou;
            }
            else
            {
                if(t[i].val - t[i-1].val <= n)
                {
                    cou += t[i].val - t[i-1].val;
                    if(t[i].id > 0)  g[t[i].id][0] = cou;
                    else g[-t[i].id][1] = cou;
                }
                else
                {
                    cou += n;
                    if(t[i].id > 0)  g[t[i].id][0] = cou;
                    else g[-t[i].id][1] = cou;
                }
            }
        }

        //for(int i = 1; i <= n; i++)   printf("i  %d %d\n", g[i][0], g[i][1]);
        //printf("cou=%d\n", cou);
        gx = n;
        gy = cou;
        memset(mat, 0, sizeof(mat));
        for(int i = 1; i <= n; i++)
          for(int j = g[i][0]; j <= g[i][1]; j++)
          {
              mat[i][j] = 1;
          }
        MaxMatch();
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值