HDU 5090 Game with Pearls(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090
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”.
2
5 1
1 2 3 4 5
6 2
1 2 3 4 5 5
Jerry
Tom
pid=5096" style="color:rgb(26,92,200); text-decoration:none">5096
pid=5094" style="color:rgb(26,92,200); text-decoration:none">5094
5093题意:
有 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(二分匹配)的更多相关文章
- HDU 2063 过山车(二分匹配入门)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...
- HDU - 1045 Fire Net(二分匹配)
Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...
- hdu 4619 Warm up 2 (二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 题意: 平面上有一些1×2的骨牌,每张骨牌要么水平放置,要么竖直放置,并且保证同方向放置的骨牌不 ...
- HDU 2063 过山车 二分匹配
解题报告:有m个女生和n个男生要结成伴坐过山车,每个女生都有几个自己想选择的男生,然后要你确定最多能组成多少对组合. 最裸的一个二分匹配,这是我第一次写二分匹配,给我最大的感受就是看那些人讲的匈牙利算 ...
- hdu 1528 Card Game Cheater (二分匹配)
Card Game Cheater Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1068 Girls and Boys (二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU - 1068 Girls and Boys(二分匹配---最大独立集)
题意:给出每个学生的标号及与其有缘分成为情侣的人的标号,求一个最大集合,集合中任意两个人都没有缘分成为情侣. 分析: 1.若两人有缘分,则可以连一条边,本题是求一个最大集合,集合中任意两点都不相连,即 ...
- [HDU 5090] Game with Pearls (贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090 题目大意:给你n个数,问你给若干个数增加c*k(c>=0)能否组成1,2,3,4,5,.. ...
- hdu 5090 Game with Pearls
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090 题意:n个数,k,给n个数加上k的正倍数或者不加,问最后能不能凑成1 到 n的序列 题目分类:暴 ...
随机推荐
- 学习RFT之:TestObject.find方法的了解与使用
第一部分:了解TestObject.find 一.TestObject.find方法的作用 1.测试过程中动态的找到测试对象(控件.标签等),使我们的测试用例不再依赖RFT自带的对象地图(Object ...
- Android 6.0权限分组
Android系统从6.0开始将权限分为一般权限和危险权限,一般权限指不涉及用户隐私的一些权限,比如Internet权限.危险权限指涉及获取用户隐私的一些操作所需要的权限,比如读取用户地理位置的权限. ...
- 微信小程序组件解读和分析:三、swiper滑块视图
swiper滑块组件说明: 滑块视图容器,用于展示图片,可以通过用户拖拽和设置自动切换属性控制图片的切换 组件的使用示例的运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? ...
- HTML——meta
http://www.cnblogs.com/jr1993/p/4542862.html
- Farseer.net轻量级开源框架 中级篇:数据绑定
导航 目 录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: DbFactory数据工厂 下一篇:Farseer.net轻量级开源框架 中级篇: ...
- magento category Ids Name
如何获取产品的分类的名称 和ids 1.对于产品的分类ids 的获取 $this->getProduct()->getCategoryIds() 2.对应产品的分类的Name 的 ...
- 扩增子分析解读6进化树 Alpha Beta多样性
分析前准备 # 进入工作目录 cd example_PE250 上一节回顾:我们的OTU获得了物种注释,并学习OTU表的各种操作————添加信息,格式转换,筛选信息. 接下来我们学习对OTU序列的 ...
- docker常用命令理解
docker help Commands: attach Attach local standard input, output, and error streams to a running con ...
- php获取文件扩展名
<?php $path = 'http://www.wstmart.net/doc.html'; $ext = getExt($path); echo $ext; // 方法1 function ...
- Colletions工具类常用方法
Collections 工具类常用方法: 排序 查找,替换操作 同步控制(不推荐,需要线程安全的集合类型时请考虑使用 JUC 包下的并发集合 排序操作 void reverse(List list)/ ...