标签:
2 4 5004 5005 5005 5006 5004 5006 5004 5006 7 4 5 2 3 1 2 2 2 4 4 2 3 3 4
3 2 3 4 5 1 3 5 6 7
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 100010; 4 int L[maxn],R[maxn],LinkX[maxn],LinkY[maxn]; 5 bool used[maxn]; 6 bool match(int u) { 7 for(int i = L[u]; i <= R[u]; ++i) { 8 if(!used[i]) { 9 used[i] = true; 10 if(LinkX[i] == -1 || match(LinkX[i])) { 11 LinkX[i] = u; 12 LinkY[u] = i; 13 return true; 14 } 15 } 16 } 17 return false; 18 } 19 int main() { 20 int kase,n; 21 scanf("%d",&kase); 22 while(kase--) { 23 scanf("%d",&n); 24 for(int i = 1; i <= n; ++i) 25 scanf("%d%d",L + i,R + i); 26 memset(LinkX,-1,sizeof LinkX); 27 memset(LinkY,-1,sizeof LinkY); 28 int ret = 0; 29 for(int i = n; i >= 1; --i) { 30 memset(used,false,sizeof used); 31 if(match(i)) ++ret; 32 } 33 printf("%d\n",ret); 34 for(int i = 1; i <= n && ret; ++i) { 35 if(LinkY[i] != -1) { 36 if(--ret) printf("%d ",i); 37 else printf("%d\n",i); 38 } 39 } 40 } 41 return 0; 42 }
HDU 3729 I'm Telling the Truth
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4764528.html