HDOJ 5090 Game with Pearls 二分图匹配
简单的二分图匹配:
每个位置可以边到这些数字甚至可以边
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
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
#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;
}
版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss
HDOJ 5090 Game with Pearls 二分图匹配的更多相关文章
- 贪心 HDOJ 5090 Game with Pearls
题目传送门 /* 题意:给n, k,然后允许给某一个数加上k的正整数倍,当然可以不加, 问你是否可以把这n个数变成1,2,3,...,n, 可以就输出Jerry, 否则输出Tom. 贪心:保存可能变成 ...
- HDU5090--Game with Pearls 二分图匹配 (匈牙利算法)
题意:给N个容器,每个容器里有一定数目的珍珠,现在Jerry开始在管子上面再放一些珍珠,放上的珍珠数必须是K的倍数,可以不放.最后将容器排序,如果可以做到第i个容器上面有i个珍珠,则Jerry胜出,反 ...
- HDOJ 5093 Battle ships 二分图匹配
二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...
- UVA 12549 - 二分图匹配
题意:给定一个Y行X列的网格,网格种有重要位置和障碍物.要求用最少的机器人看守所有重要的位置,每个机器人放在一个格子里,面朝上下左右四个方向之一发出激光直到射到障碍物为止,沿途都是看守范围.机器人不会 ...
- POJ 1274 裸二分图匹配
题意:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶,告诉每头奶牛愿意产奶的牛棚编号,求出最多能分配到的牛栏的数量. 分析:直接二分图匹配: #include<stdio.h> #includ ...
- BZOJ1433 ZJOI2009 假期的宿舍 二分图匹配
1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2375 Solved: 1005[Submit][Sta ...
- HDU1281-棋盘游戏-二分图匹配
先跑一个二分图匹配,然后一一删去匹配上的边,看能不能达到最大匹配数,不能这条边就是重要边 /*----------------------------------------------------- ...
- HDU 1083 网络流之二分图匹配
http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...
- hdu 5727 Necklace dfs+二分图匹配
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...
随机推荐
- OC学习篇之—写类别(类的扩展)
首先我们来看一下场景,如果我们现在想对一个类进行功能的扩充,我们该怎么做? 对于面向对象编程的话,首先会想到继承,但是继承有两个问题: 第一个问题:继承的前提是这个类可以被继承,因为在Java中有些类 ...
- POJ 3641 Oulipo KMP 水题
http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...
- 得到INI文件所有Section(所有节点名称)
char SectionNames[MAX_PATH],*pSectionName; ZeroMemory(SectionNames,MAX_PATH); GetPrivateProfileSecti ...
- NASM Syntax
NASM has a simplified syntax designed to let the user code with minimum overhead. In its simplest fo ...
- swift入门之TableView
IOS8更新了,oc还将继续但新增了swift语言,能够代替oc编写ios应用,本文将使用swift作为编写语言,为大家提供step by step的教程. 工具 ios每次更新都须要更新xcode, ...
- 修改QList中的item(使用下标([index])才可以获得可修改的item的引用)
QList算是最常用的集合了,今儿偶然间需要修改QList中的值,结果郁闷了.QList中提供了replace函数来替换item,但不是修改.而at().value()操作均返回的是const的ite ...
- Android OkHttp网络连接封装工具类
package com.lidong.demo.utils; import android.os.Handler; import android.os.Looper; import com.googl ...
- 在ArcEngine中使用Geoprocessing工具-执行工具
转自原文在ArcEngine中使用Geoprocessing工具-执行工具 来解析一下Geoprocessor类的Execute方法,他有两种重载,Execute(IGPProcess, ITrack ...
- ios开发事件处理之:一:UIView的拖拽
1.ios当中常⽤的事件? 触摸事件 ,加速计事件 ,远程控制事件 2.什么是响应者对象? 继承了UIResponds的对象我们称它为响应者对象 UIApplication.UIViewContro ...
- SEO那些事:一句代码一键分享网站
这是很久以前就已经写过的笔记了,有一个习惯,每次遇到一个问题,都会进行百度,然后把解决问题的关键点记录下来,有人问我,为什么更新频率如此之快,大部分都是从前积累的知识点. 其实每天工作所涉及的知识点都 ...