2014ACM上海邀请赛A解释称号
#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解释称号的更多相关文章
- [POI 2001+2014acm上海邀请赛]Gold Mine/Beam Cannon 线段树+扫描线
Description Byteman, one of the most deserving employee of The Goldmine of Byteland, is about to re ...
- HDU5092——Seam Carving(动态规划+回溯)(2014上海邀请赛重现)
Seam Carving DescriptionFish likes to take photo with his friends. Several days ago, he found that s ...
- HDU5093——Battle ships(最大二分匹配)(2014上海邀请赛重现)
Battle ships Problem DescriptionDear contestant, now you are an excellent navy commander, who is res ...
- HDU5099——Comparison of Android versions(简单题)(2014上海邀请赛重现)
Comparison of Android versionsProblem DescriptionAs an Android developer, itˇs really not easy to fi ...
- HDU5090——Game with Pearls(匈牙利算法|贪心)(2014上海邀请赛重现)
Game with Pearls Problem DescriptionTom and Jerry are playing a game with tubes and pearls. The rule ...
- [java线段树]2015上海邀请赛 D Doom
题意:n个数 m个询问 每个询问[l, r]的和, 再把[l, r]之间所有的数变为平方(模为9223372034707292160LL) 很明显的线段树 看到这个模(LLONG_MAX为922337 ...
- [java]2015上海邀请赛 B Base64
题意: 给n和一个字符串(可以有空格) 求字符串编码n次后的字符串 编码方式:字符串的每个字符转化成ASCII码, ASCII码转化成8位2进制, 将二进制数分割成6位为一组的(不够的补0), ...
- ZOJ 3820 2014ACM/ICPC牡丹江司B称号
3797714 2014 - 10 - 12 21:58 : 19 Accepted 3820 C++ 1350 70240 zz_1215 比較麻烦的一道题吧,開始的时候不停的段异常,后面知道是爆栈 ...
- “纽劢科技杯”第十六届同济大学程序设计竞赛暨上海邀请赛同步赛 J-张老师的游戏
传送门 题目描述 在空闲时间,张老师习惯性地和菜哭武玩起了取石子游戏,这次的游戏规则有些不同,在他们面前有n堆石子,其中,第i堆石子的个数为a[i],现在制定规则如下: 从张老师开始, ...
随机推荐
- C#获取设备的IP和Mac类
/// <summary> /// 此类用于获得设备的Ip和Mac /// </summary> public class Mac { [DllImport("Iph ...
- wamp在win7下64位系统memcache/memcached安装教程
折腾了1个多小时,终于搞定.操作系统时64位的,php5.3.13 类似于上一篇的xdebug安装教程~~ memcache和memcached的区别 在自己的新程序中打算全面应用memcached ...
- linux解压多个文件
方法很多种, 根据实际文件类型,位置情况进行变通: 1. for查询:for tar in *.tar.gz; do tar xvf $tar; done2. 列出文件列表,然后xargs 逐一解压: ...
- zoj 3822 Domination (可能性DP)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- 开放搜索服务OpenSearch
开放搜索服务系统架构:从系统.平台到开放服务 搜索是各类网站和数据类APP的标配功能.目前开发者一般基于开源搜索系统,例如ElasticSearch.Solr.Sphinx等自己搭建搜索服务,系统定制 ...
- ecshop首页调用某分类下的商品|assign_cat_goods()
ecshop首页调用分类下的商品其实很简单,也有模板设置那里可以设置,不过那个只可以用cat_goods.lib,不方便,所以我想看看怎么能简单的实现ecshop首页调用分类下的商品 只需要在inde ...
- Java的wait(), notify()和notifyAll()使用心得(转)
本篇文章是对java的 wait(),notify(),notifyAll()进行了详细的分析介绍,需要的朋友参考下wait(),notify()和notifyAll()都是java.lang.Obj ...
- (step7.2.1)hdu 1395(2^x mod n = 1——简单数论)
题目大意:输入一个整数n,输出使2^x mod n = 1成立的最小值K 解题思路:简单数论 1)n可能不能为偶数.因为偶数可不可能模上偶数以后==1. 2)n肯定不可能为1 .因为任何数模上1 == ...
- USACO comehome Dijkstra
USER: Kevin Samuel [kevin_s1] TASK: comehome LANG: C++ Compiling... Compile: OK Executing... Test 1: ...
- crontab,想说爱你不easy
悲剧的背景 跑自己主动化脚本的机器连不上toastserver了, 仅仅能自己写个脚本每天跑了. 当然要放在crontab里了. 5 3 * * * sh ~/nosecron.sh 更悲剧的结果 第 ...