标签:des style blog color io os ar java for
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1482 Accepted Submission(s): 740
1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 #include <iostream> 5 #include <vector> 6 #include <queue> 7 using namespace std; 8 9 #define N 1000005 10 11 int from[N], l[65], r[65]; 12 bool visited[N]; 13 int n; 14 vector<int>ve[65]; 15 16 int march(int u){ 17 int v, i; 18 for(i=0;i<ve[u].size();i++){ 19 v=ve[u][i]; 20 if(!visited[v]){ 21 visited[v]=true; 22 if(from[v]==-1||march(from[v])){ 23 from[v]=u; 24 return 1; 25 } 26 } 27 } 28 return 0; 29 } 30 31 main() 32 { 33 int t, i, j, k, x, y; 34 cin>>t; 35 while(t--){ 36 scanf("%d",&n); 37 for(i=1;i<=n;i++){ 38 scanf("%d %d",&l[i],&r[i]); 39 } 40 for(i=1;i<=n;i++) ve[i].clear(); 41 for(i=1;i<=n;i++){ 42 for(j=l[i];j<=r[i];j++){ 43 ve[i].push_back(j); 44 } 45 } 46 int num=0; 47 int ans[65]; 48 k=0; 49 memset(from,-1,sizeof(from)); 50 for(i=n;i>=1;i--){ 51 memset(visited,false,sizeof(visited)); 52 if(march(i)){ //若有增广路径 说明匹配成功 53 num++; 54 ans[k++]=i; 55 } 56 } 57 sort(ans,ans+k); 58 printf("%d\n%d",num,ans[0]); 59 for(i=1;i<k;i++) printf(" %d",ans[i]); 60 cout<<endl; 61 } 62 }
标签:des style blog color io os ar java for
原文地址:http://www.cnblogs.com/qq1012662902/p/4025065.html