去年天津赛的题目,重新看了一下题,如果今年去那场比赛,估计能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;
}