HDU5090模拟,hash
/*
HDU 5090
算是一道简单模拟题。但当中有非常深的hash思想
这是本人的第一道hash题
更是本人的第一道纸质代码不带编译不带执行提交AC的题
值得纪念 废话讲这么多之后,讲述题中思想
因为n非常小不超过100。可以开个数组记录每一个数出现多少次
因为仅仅能i+n*k变大。因此仅仅须要从1到n逐个检查
若当前检查的hash[i]=0则无解:因为不可能有其它数可以变化成它
若当前检查的hash[i]>1则必须将i变化为j=n*k+i(n>0),当中hash[j]=0代表 j 在输入的数中没有出现过由数 i 变过来的
若当前检查的hash[i]=1继续
循环一遍之后。仅仅需推断标志符号
*/ #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
using namespace std; #define input freopen("input.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define For1(i,a,b) for (i=a;i<b;i++)
#define For2(i,a,b) for (i=a;i<=b;i++)
#define Dec(i,a,b) for (i=a;i>b;i--)
#define Dec2(i,a,b) for (i=a;i>=b;i--)
#define Sca_d(x) scanf("%d",&x)
#define Sca_s(x) scanf("%s",x)
#define Sca_c(x) scanf("%c",&x)
#define Sca_f(x) scanf("%f",&x)
#define Sca_lf(x) scanf("%lf",&x)
#define Fill(x,a) memset(x,a,sizeof(x))
#define MAXN 1110 template <typename T>
T gcd(T a,T b)
{
return b==0?a:gcd(b,a%b);
} template <typename T>
T lcm(T a,T b)
{
return a/gcd(a,b)*b;
} int main()
{
int hash[MAXN];
int t,n,k,i,j,m,flag;
cin>>t;
while(t--)
{
cin>>n>>k;
Fill(hash,0);
For2(i,1,n)
Sca_d(m),hash[m]++;
flag=1;
For2(i,1,n)
if (!hash[i])
{
flag=0;
break;
}
else if (hash[i]==1) continue;
else
{
for(j=i+k;j<=n;j+=k)
if (hash[i]>1&&hash[j]==0)
{
hash[j]=1;
hash[i]--;
}
}
if (flag) cout<<"Jerry\n";
else cout<<"Tom\n";
}
return 0;
}
HDU5090模拟,hash的更多相关文章
- 【NOI】2017 蚯蚓排队(BZOJ 4943,LOJ 2303) 模拟+hash
[题目]#2303. 「NOI2017」蚯蚓排队 [题意]给定n条长度不超过6的蚯蚓,初始各自在一个队伍.m次操作:1.将i号蚯蚓和j号蚯蚓的队伍合并(保证i为队尾,j为队首).2.将i号蚯蚓和它后面 ...
- Codeforces Round #454 C. Shockers【模拟/hash】
C. Shockers time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- POJ 3087 模拟+hash
也可以用map来搞 样例推出来 就没啥问题了 (先读的是B 然后是A 被坑好久) //By SiriusRen #include <cstdio> #include <iostrea ...
- 【hash表】图书管理
[哈希和哈希表]图书管理 题目描述 图书管理是一件十分繁杂的工作,在一个图书馆中每天都会有许多新书加入.为了更方便的管理图书(以便于帮助想要借书的客人快速查找他们是否有他们所需要的书),我们需要设计一 ...
- 模拟HashMap冲突
最近看HashMap的源码,其中相同下标容易产生hash冲突,但是调试需要发生hash冲突,本文模拟hash冲突. hash冲突原理 HashMap冲突是key首先调用hash()方法: static ...
- Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference
最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ...
- Java for LeetCode 187 Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- 一起刷LeetCode1-Two Sum
感觉有必要重新刷刷题了,为以后找工作做做准备,选择LeetCode+topcoder上的Data Science Tutorials, 争取每天晚上10:00开始刷一道,复习一下相关知识点. ---- ...
- Mysq 索引优化
MYSQL支持的索引类型 BTREE索引 特点: 通过引用以B+权的结构存储数据 能够加快数据的查询速度 更适合进行范围查找 应用: 全值匹配的查询 = 匹配最左前缀的查询 匹配列前缀查询 LIKE ...
随机推荐
- QT学习 之 对话框 (四) 字体对话框、消息对话框、文件对话框、进程对话框(超详细中文注释)
QMessageBox类: 含有Question消息框.Information消息框.Warning消息框和Critical消息框等 通常有两种方式可以来创建标准消息对话框: 一种是采用“基于属性”的 ...
- ThinkPHP 3.1.2 模板中的基本语法<2>
本节课大纲: 一.导入CSS和JS文件 1.css link js scr <link rel='stylesheet' type='text/css' href='__PUBLIC__/Css ...
- poj 3176 Cow Bowling(区间dp)
题目链接:http://poj.org/problem?id=3176 思路分析:基本的DP题目:将每个节点视为一个状态,记为B[i][j], 状态转移方程为 B[i][j] = A[i][j] + ...
- Android网络开发之用tcpdump抓包
Android开发过程中,当涉及到网络通信的时候,有一些字段须要抓包获取.我之前由于SSDP设备发现的包头格式没有写对,经过抓包分析和标准包头对照发现了这个困扰我非常久的问题.总之,掌握在Androi ...
- ajax对服务器路径请求
$.post('/aaaa/bbbb/cccc', { "paraName": value}, function (data) { S ...
- Delphi启动/停止Windows服务,启动类型修改为"自动"
unit U_StartServices; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Contr ...
- php前端控制器2
Front Controllers act like centralized agents in an application whose primary area of concern is to ...
- php利用iframe实现无刷新文件上传功能
上传原理很简单就是利用表单的打开方式为iframe的name名,这样就可以在当前页面的iframe打来了,实现文件上传,再利用js返回上传结果. form target .在 action 属性中规定 ...
- 编译原理Tiny语言的定义
Here is the definition for Tiny language The Tiny lexicon is as follows: Keywords: IF ELSE WRITE R ...
- AsyncTask简单入门
关系: java.lang.Object ↳ android.os.AsyncTask<Params, Progress, Result> 概述: AsyncTask是Andr ...