日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【FZU - 2039】Pets(二分图匹配,水题)

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【FZU - 2039】Pets(二分图匹配,水题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

有n個人,m條狗,然后會給出有一些人不喜歡一些狗就不會購買,問最多能賣多少狗。。

Input

There is a single integer T in the first line of the test data indicating that there are T(T≤100) test cases. In the first line of each test case, there are three numbers n, m(0≤n,m≤100) and e(0≤e≤n*m). Here, n and m represent the number of customers and the number of pets respectively.

In the following e lines of each test case, there are two integers x(1≤x≤n), y(1≤y≤m) indicating that customer x is not interested in pet y, such that x would not buy y.

Output

For each test case, print a line containing the test case number (beginning with 1) and the maximum number of pets that can be sold out.

Sample Input

1 2 2 2 1 2 2 1

Sample Output

Case 1: 2

解題報告:

? ?隨便匈牙利一下。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e2 + 5; int nxt[MAX]; bool line[MAX][MAX]; bool use[MAX]; int n,m,e; bool find(int x) {for(int i = 1; i<=m; i++) {if(!use[i]&& line[x][i]) {use[i]=1;if(!nxt[i] || find(nxt[i])) {nxt[i] = x;return 1;}}}return 0; }int match() {int res = 0 ;for(int i = 1; i<=n; i++) {memset(use,0,sizeof use);if(find(i)) res++;}return res; } int main() {int t,iCase=0;cin>>t;while(t--) {memset(line,1,sizeof line);memset(nxt,0,sizeof nxt);scanf("%d%d%d",&n,&m,&e);for(int a,b,i = 1; i<=e; i++) {scanf("%d%d",&a,&b);line[a][b]=0;}printf("Case %d: %d\n",++iCase,match());}return 0 ; }

?

總結

以上是生活随笔為你收集整理的【FZU - 2039】Pets(二分图匹配,水题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。