HDU 4619 Warm up 2 最大独立集
2015-05-22 23:43
363 查看
Warm up 2
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1886 Accepted Submission(s): 855
Problem Description
Some 1×2 dominoes are placed on a plane. Each dominoe is placed either horizontally or vertically. It's guaranteed the dominoes in the same direction are not overlapped, but horizontal and vertical dominoes may overlap with each other. You task is to remove
some dominoes, so that the remaining dominoes do not overlap with each other. Now, tell me the maximum number of dominoes left on the board.
Input
There are multiple input cases.
The first line of each case are 2 integers: n(1 <= n <= 1000), m(1 <= m <= 1000), indicating the number of horizontal and vertical dominoes.
Then n lines follow, each line contains 2 integers x (0 <= x <= 100) and y (0 <= y <= 100), indicating the position of a horizontal dominoe. The dominoe occupies the grids of (x, y) and (x + 1, y).
Then m lines follow, each line contains 2 integers x (0 <= x <= 100) and y (0 <= y <= 100), indicating the position of a horizontal dominoe. The dominoe occupies the grids of (x, y) and (x, y + 1).
Input ends with n = 0 and m = 0.
Output
For each test case, output the maximum number of remaining dominoes in a line.
Sample Input
2 3 0 0 0 3 0 1 1 1 1 3 4 5 0 1 0 2 3 1 2 2 0 0 1 0 2 0 4 1 3 2 0 0
Sample Output
4 6
Author
SYSU
Source
2013 Multi-University Training Contest 2
给出坐标系上一些点,在里面放着一些1*2的多米诺骨牌。
现在从上面取走一些方块,使摆放不能重合。最多可以保留多少互不重合的方块。
二分图最大独立集。
/** Author: ☆·aosaki(*’(OO)’*) niconiconi★ **/ //#pragma comment(linker, "/STACK:1024000000,1024000000") //#include<bits/stdc++.h> #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <algorithm> #include <functional> #include <cmath> #include <vector> #include <queue> #include <map> #include <set> #include <list> #include <stack> //#include <tuple> #define ALL(v) (v).begin(),(v).end() #define foreach(i,v) for (__typeof((v).begin())i=(v).begin();i!=(v).end();i++) #define SIZE(v) ((int)(v).size()) #define mem(a) memset(a,0,sizeof(a)) #define mem1(a) memset(a,-1,sizeof(a)) #define lp(k,a) for(int k=1;k<=a;k++) #define lp0(k,a) for(int k=0;k<a;k++) #define lpn(k,n,a) for(int k=n;k<=a;k++) #define lpd(k,n,a) for(int k=n;k>=a;k--) #define sc(a) scanf("%d",&a) #define sc2(a,b) scanf("%d %d",&a,&b) #define lowbit(x) (x&(-x)) #define ll long long #define pi pair<int,int> #define vi vector<int> #define PI acos(-1.0) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define TT cout<<"*****"<<endl; #define TTT cout<<"********"<<endl; inline int gcd(int a,int b) { return a==0?b:gcd(b%a,a); } #define MAXN 2555 using namespace std; int link[MAXN]; bool used[MAXN]; vector<int> vec[MAXN]; int n,m; bool dfs(int u) { lp0(i,vec[u].size()) { if(!used[vec[u][i]]) { used[vec[u][i]]=1; if(link[vec[u][i]]==-1 || dfs(link[vec[u][i]])) { link[vec[u][i]]=u; return 1; } } } return 0; } int hun() { int u; int re=0; mem1(link); lp0(u,n) { mem(used); if(dfs(u)) re++; } return re; } struct aoi1 { int x,y; }p1[2010]; struct aoi2 { int x,y; }p2[2010]; int main() { //freopen("in.txt","r",stdin); int x,y; while(~sc2(n,m)) { if(n==0&&m==0)break; lp0(i,n) { sc2(p1[i].x,p1[i].y); } lp0(i,m) { sc2(p2[i].x,p2[i].y); } lp0(i,n) vec[i].clear(); lp0(i,n) { lp0(j,m) { int x1=p1[i].x; int y1=p1[i].y; int x2=p2[j].x; int y2=p2[j].y; if( (x1==x2 && y1==y2)||(x1==x2 && y1==y2+1)||(x1+1==x2 && y1==y2)||(x1+1==x2 && y1==y2+1) ) vec[i].pb(j); } } printf("%d\n",n+m-hun()); } return 0; }
相关文章推荐
- HDU 4619 Warm up 2 最大独立集
- hdu 4619 Warm up 2_最大独立集
- HDU 4619 Warm up 2(贪心、并查集 | 二分图最大独立集)
- HDU 4619 Warm up 2(最大独立集)
- hdu 4619 Warm up 2 (二分图最大独立集)
- hdu 4619 Warm up 2_最大独立集
- HDU 4619 —— Warm up 2(二分图最大匹配)
- hdu 4619—二分图求最大独立集
- HDU 4619 Warm up 2(最大流或二分匹配)
- hdu 4619 Warm up 2 ( 二分图最大匹配 )
- HDU 4619 Warm up 2(点独立集)
- HDU 4619 (二分图匹配 最大独立集)
- HDU-4619:Warm up 2(二分图最大独立集)
- hdu 4619 Warm up 2(最大独立点集,二分匹配,4级)
- hdu 4619 Warm up 2(二分图最大匹配)
- hdu 4619 Warm up 2 ( 二分图最大匹配 )
- hdu1068 Girls and Boys (二分图最大独立集)
- HDU 1068 Girls and Boys【最大独立集】
- hdu 2768 Cat vs. Dog 最大独立集(最大匹配)
- hdu 1068 (最大独立集)