Game with Pearls(二分图)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090

#include
#include
#include
#include
using namespace std;

int vis[105],g[105][105],link[105];
int t,n,k,a;

int erfen(int u){
	for(int i = 1;i<=n;++i){
		if(g[i][u] == 1&&vis[i] == 0){
			vis[i] = 1;
			if(link[i] == 0||erfen(link[i]) == 1){
				link[i] = u;
				return 1;
			}
		}
	}
	return 0;
}

int solve(){
	memset(link,0,sizeof(link));
	int res = 0;
	for(int i = 1;i<=n;++i){
		memset(vis,0,sizeof(vis));
		if(erfen(i) == 1)  ++res;
	}
	return res;
}

int main(){
	cin>>t;
	while(t--){
		cin>>n>>k;
		memset(g,0,sizeof(g));
		for(int i = 1;i<=n;++i){
			cin>>a;
		    while(a <= n){
		    	g[i][a] = 1;
		    	a += k;
			}
		}
		if(solve() == n){
			cout<<"Jerry\n";
		}
		else{
			cout<<"Tom\n";
		}
	}
	return 0;
}

 

你可能感兴趣的:(二分图)