uva 6959 Judging hash
Judging
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=114147
Description
Input
The input consists of:
one line with one integer n (1≤n≤105), the number of submissions;
n lines, each with a result of the judging by DOMjudge, in arbitrary order;
n lines, each with a result of the judging by Kattis, in arbitrary order.
Each result is a string of length between 5 and 15 characters (inclusive) consisting of lowercase letters.
Output
Output one line with the maximum number of judging results that could have been the same for both systems.
Sample Input
5
correct
wronganswer
correct
correct
timelimit
wronganswer
correct
timelimit
correct
timelimit
Sample Output
4
HINT
题意
有两个机器,每个机器都会返回n个串,然后问你有多少个串是在两个地方都出现过
题解:
双hash一下,然后用map存一下,然后搞一搞就好了……
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int get_hash(char *key)
{
ll N=;
long long h=;
while(*key)
h=(h*+(*key++)+N)%N;
return h%N;
}
int get_hash2(char *key)
{
ll N=;
long long h=;
while(*key)
h=(h*+(*key++)+N)%N;
return h%N;
}
char s[];
map< pair<int,int> ,int>H;
int main()
{
int n=read();
for(int i=;i<n;i++)
{
scanf("%s",s);
pair<int,int> a;
a.first=get_hash(s);
a.second=get_hash2(s);
H[a]++;
}
int ans=;
for(int i=;i<n;i++)
{
scanf("%s",s);
pair<int,int> a;
a.first=get_hash(s);
a.second=get_hash2(s);
if(H[a])
{
ans++;
H[a]--;
}
}
printf("%d\n",ans);
}
uva 6959 Judging hash的更多相关文章
- UVALive 6959 - Judging Troubles
给两组字符串,最多有多少对相同. map做映射判断一下. #include <iostream> #include <cstdio> #include <map> ...
- [UVA] 704 Colour Hash
所谓"周界搜索",练习搜索的好题,双向宽搜/迭代加深均可,还有很多细节有待完善,判重有比set更优的结构,宽搜还没写,先存一下. //Writer:GhostCai &&a ...
- UVa 10029 hash + dp
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 10798 - Be wary of Roses (bfs+hash)
10798 - Be wary of Roses You've always been proud of your prize rose garden. However, some jealous f ...
- UVA 257 - Palinwords(弦HASH)
UVA 257 - Palinwords 题目链接 题意:输出一个文本里面的palinword,palinword的定义为.包括两个不同的回文子串,而且要求回文子串不能互相包括 思路:对于每一个单词推 ...
- UVa Live 3942 Remember the Word - Hash - 动态规划
题目传送门 高速路出口I 高速路出口II 题目大意 给定若干种短串,和文本串$S$,问有多少种方式可以将短串拼成长串. 显然,你需要一个动态规划. 用$f[i]$表示拼出串$S$前$i$个字符的方案数 ...
- UVa 11019 Matrix Matcher - Hash
题目传送门 快速的vjudge传送门 快速的UVa传送门 题目大意 给定两个矩阵S和T,问T在S中出现了多少次. 不会AC自动机做法. 考虑一维的字符串Hash怎么做. 对于一个长度为$l$的字符串$ ...
- UVa 11996 Jewel Magic (splay + Hash + 二分)
题意:给定一个长度为n的01串,你的任务是依次执行如表所示的m条指令: 1 p c 在第p个字符后插入字符,p = 0表示在整个字符串之前插入2 p 删除第p个字符,后面的字符往前移3 p1 p2反转 ...
- UVA 11557 - Code Theft (KMP + HASH)
UVA 11557 - Code Theft 题目链接 题意:给定一些代码文本.然后在给定一个现有文本,找出这个现有文本和前面代码文本,反复连续行最多的这些文本 思路:把每一行hash成一个值.然后对 ...
随机推荐
- Linux端口占用
1.netstat netstat -anp | grep 23232 Sample: [root@BICServer 0825]# netstat -anp | grep 23232 tcp 0 0 ...
- 如何在Linux下用C/C++语言操作数据库sqlite3(很不错!设计编译链接等很多问题!)
from : http://blog.chinaunix.NET/uid-21556133-id-118208.html 安装Sqlite3: 从www.sqlite.org上下载Sqlite3.2. ...
- nginx与PHP的关系和交互方式【转】
nginx与PHP的关系. 对比, apache和PHP的关系, 将PHP安装成apache的一个功能模块, 导致的结果, 对外只有一个apache程序, PHP并不独立出现, 仅仅是apache的模 ...
- oracle命令生成AWR报告
--命令生成AWR报告oracle@linux:~> sqlplus / as sysdba SQL*Plus: Release 11.1.0.7.0 - Production on Fri A ...
- Xcode及模拟器SDK下载
http://blog.csdn.net/zhangao0086/article/details/38491271 吐槽下,百度打着无限分享的旗号,却又让分享资源过期,让分享者持续维护 如果你嫌在Ap ...
- centos7 lvs+keepalived nat模式
1.架构图 3.地址规划 主机名 内网ip 外网ip lvs-master 192.168.137.111(仅主机)eth1 172.16.76.111(桥接)eth0 lvs-slave 192 ...
- js基础练习(四)
练习: 通过循环按行顺序为一个5×5的二维数组a赋1到25的自然数,然后输出该数组的左下半三角.试编程. 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
- wordpress后台加载速度异常缓慢排查记录(原创)
原因在于在function.php函数中加入了下面的代码导致了缓慢: //停用版本更新通知remove_action('load-update-core.php', 'wp_update_themes ...
- js获取json对象中的key和value,并组成新数组
//比如有一个json var json = {"name" : "Tom", "age" : 18}; //想分别获取它的key 和 va ...
- 【PAT】1012. 数字分类 (20)
1012. 数字分类 (20) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算 ...