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

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”.
 
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
 
Recommend

题意:

有 n 个容器,每一个里面有一些珍珠。

能够在随意容器中加入 k 的倍数个珍珠。

问终于能否使得每一个容器分别有1 ~ n颗珍珠。

代码例如以下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define MAXN 177
int N;
int g[MAXN][MAXN], linker[MAXN];
bool used[MAXN];
int dfs(int L)//从左边開始找增广路径
{
int R;
for(R = 1 ; R <= N ; R++)//这个顶点编号从0開始。若要从1開始须要改动
{
if(g[L][R]!=0 && !used[R])
{
//找增广路。反向
used[R]=true;
if(linker[R] == -1 || dfs(linker[R]))
{
linker[R]=L;
return 1;
}
}
}
return 0;//这个不要忘了。常常忘记这句
}
int hungary()
{
int res = 0 ;
memset(linker,-1,sizeof(linker));
for(int L = 1; L <= N; L++)
{
memset(used,0,sizeof(used));
if(dfs(L))
res++;
}
return res;
}
int main()
{
int t;
int k, res, tt;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&N,&k);
memset(g,0,sizeof(g));
for(int i = 1 ; i <= N ; i++ )
{
scanf("%d",&tt);
while(tt <= N)
{
g[tt][i] = 1;
tt+=k;
}
}
res = hungary();
if(res == N)
{
printf("Jerry\n");
}
else
{
printf("Tom\n");
}
}
return 0 ;
}

HDU 5090 Game with Pearls(二分匹配)的更多相关文章

  1. HDU 2063 过山车(二分匹配入门)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...

  2. HDU - 1045 Fire Net(二分匹配)

    Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...

  3. hdu 4619 Warm up 2 (二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 题意: 平面上有一些1×2的骨牌,每张骨牌要么水平放置,要么竖直放置,并且保证同方向放置的骨牌不 ...

  4. HDU 2063 过山车 二分匹配

    解题报告:有m个女生和n个男生要结成伴坐过山车,每个女生都有几个自己想选择的男生,然后要你确定最多能组成多少对组合. 最裸的一个二分匹配,这是我第一次写二分匹配,给我最大的感受就是看那些人讲的匈牙利算 ...

  5. hdu 1528 Card Game Cheater (二分匹配)

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. hdu 1068 Girls and Boys (二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDU - 1068 Girls and Boys(二分匹配---最大独立集)

    题意:给出每个学生的标号及与其有缘分成为情侣的人的标号,求一个最大集合,集合中任意两个人都没有缘分成为情侣. 分析: 1.若两人有缘分,则可以连一条边,本题是求一个最大集合,集合中任意两点都不相连,即 ...

  8. [HDU 5090] Game with Pearls (贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090 题目大意:给你n个数,问你给若干个数增加c*k(c>=0)能否组成1,2,3,4,5,.. ...

  9. hdu 5090 Game with Pearls

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090 题意:n个数,k,给n个数加上k的正倍数或者不加,问最后能不能凑成1 到 n的序列 题目分类:暴 ...

随机推荐

  1. 网页内容爬取:如何提取正文内容 BEAUTIFULSOUP的输出

    创建一个新网站,一开始没有内容,通常需要抓取其他人的网页内容,一般的操作步骤如下: 根据url下载网页内容,针对每个网页的html结构特征,利用正则表达式,或者其他的方式,做文本解析,提取出想要的正文 ...

  2. LDA主题模型(理解篇)

    何谓“主题”呢?望文生义就知道是什么意思了,就是诸如一篇文章.一段话.一个句子所表达的中心思想.不过从统计模型的角度来说, 我们是用一个特定的词频分布来刻画主题的,并认为一篇文章.一段话.一个句子是从 ...

  3. UI布局术语

    horizontal, vertical top, left, bottom, right UIEdgeInsets margin与padding Interpreting Values Values ...

  4. UEditer的使用

    1.首先到官网下载http://ueditor.baidu.com/website/download.html#ueditor 2.然后把解压后的文件复制到项目中(放在UEditer中),如图 3.在 ...

  5. C# HttpWebRequest Post Get 请求数据

    Post请求 1 //data 2 string cookieStr = "Cookie信息"; 3 string postData = string.Format("u ...

  6. Java实现打包文件

    把文件打包到压缩包里 public void zip (String... files) throws IOException { //创建文件打包流对象 ZipOutputStream zos = ...

  7. Python自学-2-python解释器

    写python源文件,以.py为后缀名 用python解释器去执行.py文件 python解释器 CPython:官方版本,由C语言开发的,下载默认就是这个,使用最广的解释器.   用>> ...

  8. 牛客多校Round 9

    Solved:1 rank:112 E. Music Game 题解说有个非简化的原题 bzoj4318 #include <bits/stdc++.h> using namespace ...

  9. 【nginx】解决nginx搭建图片服务器访问图片404

    图片通过ftp服务上传到/home/ftpuser/www/images目录下后访问 http://192.168.128.128/images/xxx.jpg 还是 404 NOT FOUND ,解 ...

  10. post请求重定向到get请求问题

    springMVC默认重定向是get请求,我在方法注解中没有指定method是post还是get请求,这样就可以接收到post重定向来的请求,也可以接收到页面传来的get请求,如果要传参,可以使用mo ...