首页 > 其他 > 详细

二分图题目泛做(为了对应陈学姐的课件)

时间:2016-01-26 21:59:29      阅读:248      评论:0      收藏:0      [点我收藏+]

题1:BZOJ1854 SCOI2010游戏

每个属性x,y分别向i连条边,匹配到不能匹配为止。

输出即可。

技术分享
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <iostream>
 5 #include <algorithm>
 6 
 7 using namespace std;
 8 
 9 const int N = 1000000 + 5;
10 
11 int tim = 0, n, tot = 0;
12 int first[N], next[N<<1];
13 int u[N<<1], v[N<<1];
14 int used[N], girl[N];
15 
16 void Add(int s, int t){
17   ++ tot;
18   u[tot] = s; v[tot] = t;
19   next[tot] = first[u[tot]];
20   first[u[tot]] = tot;
21 }
22 
23 bool find(int now){
24   for(int i = first[now]; i; i = next[i]){
25     if(used[v[i]] != tim){
26       used[v[i]] = tim;
27 
28       if(girl[v[i]] == 0 || find(girl[v[i]])){
29         girl[v[i]] = now;
30         return true;
31       }
32     }
33   }
34 
35   return false;
36 }
37 
38 #define ONLINE_JUDGE
39 int main(){
40 #ifndef ONLINE_JUDGE
41   freopen("game.in", "r", stdin);
42   freopen("game.out", "w", stdout);
43 #endif
44   
45   int x, y;
46   
47   scanf("%d", &n);
48   for(int i = 1; i <= n; ++ i){
49     scanf("%d%d", &x, &y);
50     Add(x, i); Add(y, i);
51   }
52 
53   int ans = 0;
54   for(int i = 1; i <= 10000; ++ i){
55     ++ tim;
56     if(find(i))
57       ++ ans;
58     else break;
59   }
60 
61   printf("%d\n", ans);
62 
63 #ifndef ONLINE_JUDGE
64   fclose(stdin); fclose(stdout);
65 #endif
66   return 0;
67 }
BZOJ 1854

 

二分图题目泛做(为了对应陈学姐的课件)

原文:http://www.cnblogs.com/sxprovence/p/5161589.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!