HDU ACM 5090 Game with Pearls->二分图最大匹配或?

题意:Jerry、Tom玩游戏,给你出n个盒子,a[ i ]表示初始时,第i个中小球个数。之后Jerry可在每个盒子中加入0或k倍的小球,完成后,Jerry可以重排盒子的顺序,若能使第i个盒子中有i个小球,则Jerry获胜,输出“Jerry”,否则输出“Tom” 。

分析:首先统计每种数量的球有多少个盒子,然后从小到大分过去,剩下的盒子放到i+k的位置,这样扫描一遍数组,若有超过一个及一个以上数量的球不能找到对应的盒子则Tom赢,否则Jerry赢。

#include<iostream>
using namespace std;

int main()
{
	int M,N,K,x,i;
	int cnt[105];
	bool f;

	ios::sync_with_stdio(false);
	cin>>M;
	while(M--)
	{
		cin>>N>>K;
		memset(cnt,0,sizeof(cnt));
		for(i=0;i<N;i++)
			cnt[cin>>x,x]++;

		f=true;
		for(i=1;i<=N;i++)
		{
			if(!cnt[i])
			{
				f=false;
				break;
			}
			cnt[i+K]+=cnt[i]-1;
		}
		if(f)
			cout<<"Jerry"<<endl;
		else
			cout<<"Tom"<<endl;
	}
    return 0;
}
时间: 2024-07-30 22:03:58

HDU ACM 5090 Game with Pearls->二分图最大匹配或?的相关文章

hdu 5090 Game with Pearls(最大匹配)

Game with Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 196    Accepted Submission(s): 120 Problem Description Tom and Jerry are playing a game with tubes and pearls. The rule of the g

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 Problem Description Tom and Jerry are playing a game with tubes a

HDU ACM 1281 棋盘游戏-&gt;二分图最大匹配(匈牙利算法实践)

分析:该題可以用x坐标去匹配y坐标,匹配成功一次就是一个可放棋子的点,最后求得的的二分图最大匹配就是可以放的最大棋子数.求二分图的最大匹配使用匈牙利算法.之后通过删除一条边来判断一个点是否为关键点,若删边后,最大匹配数不变则不是,否则是,通过分别删除每个点进行测试,最终即可算出关键点的个数. #include<iostream> using namespace std; #define N 102 int map[N][N]; //记录连接x和y的边 bool vis[N]; //记录y中节点

HDU ACM 1083 Courses 二分图最大匹配

题意:p门课,每门课有若干学生,要为每门课分配一名课代表,每个学生只能担任一门课的课代表,若每个课都能找到课代表,则输出"YES",否则"NO". 分析:二分图的最大匹配,对课程.学生关系建立一个图,进行二分图最大匹配,当最大匹配数==课程数时说明能够满足要求,否则不能. #include<iostream> using namespace std; #define N 303 bool cs[N][N]; //cs[i][j]表示学生j是否选i这个课程

[HDU] 2063 过山车(二分图最大匹配)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2063 女生为X集合,男生为Y集合,求二分图最大匹配数即可. 1 #include<cstdio> 2 #include<iostream> 3 #include<string.h> 4 #include<algorithm> 5 #include<math.h> 6 #include<stdbool.h> 7 #include<ti

杭电HDU ACM Uncle Tom&#39;s Inherited Land*(二分图匹配 建模)

Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2496    Accepted Submission(s): 1028 Special Judge Problem Description Your old uncle Tom inherited a piece of land f

hdu 2063 过山车(二分图匹配最大匹配数模板)

过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10776    Accepted Submission(s): 4748 Problem Description RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做par

HDU 1528 (二分图最大匹配 + 最小覆盖, 14.07.17)

Problem Description Adam and Eve play a card game using a regular deck of 52 cards. The rules are simple. The players sit on opposite sides of a table, facing each other. Each player gets k cards from the deck and, after looking at them, places the c

HDU 2444 The Accomodation of Students 二分图判定+最大匹配

题目来源:HDU 2444 The Accomodation of Students 题意:n个人是否可以分成2组 每组的人不能相互认识 就是二分图判定 可以分成2组 每组选一个2个人认识可以去一个双人间 最多可以有几组 思路:二分图判定+最大匹配 #include <cstdio> #include <cstring> #include <vector> using namespace std; const int maxn = 550; int vis[maxn];