HDOJ 5090 Game with Pearls 二分图匹配
来源:互联网 发布:json 遍历map 编辑:程序博客网 时间:2024/05/19 01:33
简单的二分图匹配:
每一个位置的数可能边成那些数连边即可
Game with Pearls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 122 Accepted Submission(s): 85
Problem Description
Tom and Jerry are playing a game with tubes and pearls. The rule of the game is:
1) Tom and Jerry come up together with a number K.
2) Tom provides N tubes. Within each tube, there are several pearls. The number of pearls in each tube is at least 1 and at most N.
3) Jerry puts some more pearls into each tube. The number of pearls put into each tube has to be either 0 or a positive multiple of K. After that Jerry organizes these tubes in the order that the first tube has exact one pearl, the 2nd tube has exact 2 pearls, …, the Nth tube has exact N pearls.
4) If Jerry succeeds, he wins the game, otherwise Tom wins.
Write a program to determine who wins the game according to a given N, K and initial number of pearls in each tube. If Tom wins the game, output “Tom”, otherwise, output “Jerry”.
1) Tom and Jerry come up together with a number K.
2) Tom provides N tubes. Within each tube, there are several pearls. The number of pearls in each tube is at least 1 and at most N.
3) Jerry puts some more pearls into each tube. The number of pearls put into each tube has to be either 0 or a positive multiple of K. After that Jerry organizes these tubes in the order that the first tube has exact one pearl, the 2nd tube has exact 2 pearls, …, the Nth tube has exact N pearls.
4) If Jerry succeeds, he wins the game, otherwise Tom wins.
Write a program to determine who wins the game according to a given N, K and initial number of pearls in each tube. If Tom wins the game, output “Tom”, otherwise, output “Jerry”.
Input
The first line contains an integer M (M<=500), then M games follow. For each game, the first line contains 2 integers, N and K (1 <= N <= 100, 1 <= K <= N), and the second line contains N integers presenting the number of pearls in each tube.
Output
For each game, output a line containing either “Tom” or “Jerry”.
Sample Input
2 5 1 1 2 3 4 5 6 2 1 2 3 4 5 5
Sample Output
Jerry Tom
Source
2014上海全国邀请赛——题目重现(感谢上海大学提供题目)
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn=110;int n,K;struct Edge{ int to,next;}edge[maxn*maxn];int Adj[maxn],Size;void init(){ memset(Adj,-1,sizeof(Adj)); Size=0;}void add_edge(int u,int v){ edge[Size].to=v; edge[Size].next=Adj[u]; Adj[u]=Size++;}int linker[maxn];bool used[maxn];bool dfs(int u){ for(int i=Adj[u];~i;i=edge[i].next) { int v=edge[i].to; if(!used[v]) { used[v]=true; if(linker[v]==-1||dfs(linker[v])) { linker[v]=u; return true; } } } return false;}int hungary(){ int res=0; memset(linker,-1,sizeof(linker)); for(int u=1;u<=n;u++) { memset(used,false,sizeof(used)); if(dfs(u)) res++; } return res;}int a[maxn];int main(){ int T_T; scanf("%d",&T_T); while(T_T--) { scanf("%d%d",&n,&K); init(); for(int i=1;i<=n;i++) { scanf("%d",a+i); for(int j=0;a[i]+j*K<=n;j++) { int v=a[i]+j*K; add_edge(i,v); } } int pp=hungary(); //cout<<"pp: "<<pp<<endl; if(pp==n) puts("Jerry"); else puts("Tom"); } return 0;}
0 0
- HDOJ 5090 Game with Pearls 二分图匹配
- hdoj 5090 Game with Pearls 【二分图最大匹配】
- hdoj.5090 Game with Pearls【二分图匹配】 2015/08/14
- 【二分匹配】 HDU 5090 Game with Pearls
- hdu 5090 Game with Pearls (二分匹配)
- HDOJ 题目5090 Game with Pearls(二分图)
- HDU 5090--Game with Pearls【二分图最大匹配】
- Hdu 5090 Game with Pearls(二分匹配)
- HDU 5090 Game with Pearls(二分匹配)
- HDU 5090 Game with Pearls(二分匹配)
- HDU 5090 Game with Pearls【贪心||模拟||二分匹配】
- HDU ACM 5090 Game with Pearls->二分图最大匹配或?
- hdoj5090Game with Pearls【二分图最大匹配】
- hdu5090Game with Pearls(二分图匹配)
- hdu 5090 Game with Pearls(最大匹配)
- hdu 5090 Game with Pearls(最大匹配)
- HDU 5090 Game with Pearls(贪心, 二部图最大匹配)
- hdu 5090 Game with Pearls
- Android中导致小米系列手机直接崩溃的主要原因。
- Intent 传递InputStream、Bitmap
- 浅谈 PHP 与手机 APP 开发(API 接口开发)
- C语言赋值运算符
- javascript 数组对象中的迭代方法
- HDOJ 5090 Game with Pearls 二分图匹配
- 第十周项目一 输入1+2形式的式子
- 点击超链接不跳转的方式
- <s:iterator>使用status获取当前遍历数据的行数、序号等操作
- 第10周项目2之观察输出结果
- 食物API接口免费开放-APP数据接口
- iOS 开发 内存管理系列文章
- 游标cursor
- C语言逗号运算符