#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int M=510;
int m,n;
int map[M][M], match[M], chk[M]; int dfs(int p)
{
int i;
for(i=1;i<=m;i++)
if( map[p][i] && chk[i]==0 )
{
chk[i]=1;
if( match[i]==0 || dfs( match[i] ) )
{
match[i]=p;
return 1;
}
}
return 0;
} int solve()
{
int i,res;
for(i=1,res=0; i<=n; i++)
{
memset(chk,0,sizeof(chk));
res+=dfs(i);
}
return res;
} int main()
{
// freopen("in","r",stdin);
// freopen("out","w",stdout); int k,i,x,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
memset(map,0,sizeof(map));
memset(match,0,sizeof(match));
for(i=1;i<=n;i++)
{
scanf("%d",&x);
while(x<=n){
map[i][x]=1;
x+=k;
}
}
m=n; if(solve()==n)
printf("Jerry\n");
else
printf("Tom\n");
}
return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

2014ACM上海邀请赛A解释称号的更多相关文章

  1. [POI 2001+2014acm上海邀请赛]Gold Mine/Beam Cannon 线段树+扫描线

    Description  Byteman, one of the most deserving employee of The Goldmine of Byteland, is about to re ...

  2. HDU5092——Seam Carving(动态规划+回溯)(2014上海邀请赛重现)

    Seam Carving DescriptionFish likes to take photo with his friends. Several days ago, he found that s ...

  3. HDU5093——Battle ships(最大二分匹配)(2014上海邀请赛重现)

    Battle ships Problem DescriptionDear contestant, now you are an excellent navy commander, who is res ...

  4. HDU5099——Comparison of Android versions(简单题)(2014上海邀请赛重现)

    Comparison of Android versionsProblem DescriptionAs an Android developer, itˇs really not easy to fi ...

  5. HDU5090——Game with Pearls(匈牙利算法|贪心)(2014上海邀请赛重现)

    Game with Pearls Problem DescriptionTom and Jerry are playing a game with tubes and pearls. The rule ...

  6. [java线段树]2015上海邀请赛 D Doom

    题意:n个数 m个询问 每个询问[l, r]的和, 再把[l, r]之间所有的数变为平方(模为9223372034707292160LL) 很明显的线段树 看到这个模(LLONG_MAX为922337 ...

  7. [java]2015上海邀请赛 B Base64

    题意: 给n和一个字符串(可以有空格) 求字符串编码n次后的字符串 编码方式:字符串的每个字符转化成ASCII码, ASCII码转化成8位2进制,    将二进制数分割成6位为一组的(不够的补0), ...

  8. ZOJ 3820 2014ACM/ICPC牡丹江司B称号

    3797714 2014 - 10 - 12 21:58 : 19 Accepted 3820 C++ 1350 70240 zz_1215 比較麻烦的一道题吧,開始的时候不停的段异常,后面知道是爆栈 ...

  9. “纽劢科技杯”第十六届同济大学程序设计竞赛暨上海邀请赛同步赛 J-张老师的游戏

    传送门 题目描述     在空闲时间,张老师习惯性地和菜哭武玩起了取石子游戏,这次的游戏规则有些不同,在他们面前有n堆石子,其中,第i堆石子的个数为a[i],现在制定规则如下:     从张老师开始, ...

随机推荐

  1. 【Cloud Foundry】Could Foundry学习(三)——Router

    在阅读的过程中有不论什么问题.欢迎一起交流 邮箱:1494713801@qq.com    QQ:1494713801 一.概述 Router组件在Cloud Foundry中是对全部进来的Reque ...

  2. UVA 11324 - The Largest Clique(强连通分量+缩点)

    UVA 11324 - The Largest Clique 题目链接 题意:给定一个有向图,要求找一个集合,使得集合内随意两点(u, v)要么u能到v,要么v能到u,问最大能选几个点 思路:强连通分 ...

  3. MYSQL正在使用select发现现场记录方法,包括一个逗号分隔的字符串

    首先,我们创建一个逗号分隔字符串. CREATE TABLE test(id int(6) NOT NULL AUTO_INCREMENT,PRIMARY KEY (id),pname VARCHAR ...

  4. Android获取SIM卡信息--TelephonyManager

    1>获得TelephonyManager  TelephonyManager telMgr = (TelephonyManager) getSystemService(TELEPHONY_SER ...

  5. <EditText /> This text field does not specify an inputType or a hint

    我是一个警告,xml代码是: <EditText android:id="@+id/str_ipaddress" android:layout_width="wra ...

  6. Java 并发编程(三)为线程安全类中加入新的原子操作

    Java 类库中包括很多实用的"基础模块"类.通常,我们应该优先选择重用这些现有的类而不是创建新的类.:重用能减少开发工作量.开发风险(由于现有类都已经通过測试)以及维护成本.有时 ...

  7. PHP计算中文字符串长度 、截取相应中文字符串

    PHP计算字符串长度     及其   截取相应中文字符串 计算字符长度: $gouWu = '美日汇http://www.hnzyxok.com/'; echo mb_strlen($gouWu,' ...

  8. MVC区域 vs2013 mvc 搭建基架项

    http://www.it165.net/pro/html/201404/12822.html

  9. Eclipse SVN 安装注意事项

    1. 下载SVN 插件 打开 Eclipse , 菜单条 Help ->  Install New Software  在 Work with 这里加入网址 : http://subclipse ...

  10. SQL注入的原理解说,挺好!

    原文地址:http://www.cnblogs.com/rush/archive/2011/12/31/2309203.html 1.1.1 总结 前几天,国内最大的程序猿社区CSDN网站的用户数据库 ...