https://codeforces.com/problemset/problem/4/C

用来哈希的一道题目,用map也可以强行过,但是性能慢了6倍,说明是在字符串比较的时候花费了接近6倍的时间。

假如时间性能允许的话不妨用map存hash值,这样就可以让他自然溢出了。基数我喜欢选23333,溢出选择ll自然溢出(反正是map存的可以是负的)

自带hash型map,也是慢到感人。

#include<bits/stdc++.h>
using namespace std; int n;
string s;
unordered_map<string,int>m; int main(){
scanf("%d",&n);
while(n--){
cin>>s;
m[s]++;
if(m[s]==)
printf("OK\n");
else
printf("%s%d\n",s.c_str(),m[s]-);
} }

自写传说中(不满足递推的但是分布很不错的)DJB哈希,时间性能非常不错。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
char s[]; map<ll,int> m; ll DJBhash(){
ll hash=;
int l=strlen(s);
for(int i=;i<l;i++){
hash=((hash<<)+hash)+s[i];
}
return hash;
} int main(){
scanf("%d",&n);
while(n--){
scanf("%s",s);
ll res=DJBhash();
int t=m[res]++;
if(t==)
printf("OK\n");
else
printf("%s%d\n",s,t);
} }

(水题)Codeforces - 4C - Registration system的更多相关文章

  1. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  2. 水题 Codeforces Round #300 A Cutting Banner

    题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...

  3. 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas

    题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...

  4. 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas

    题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...

  5. 水题 Codeforces Round #303 (Div. 2) A. Toy Cars

    题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...

  6. 水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift

    题目传送门 /* 水题:vector容器实现插入操作,暴力进行判断是否为回文串 */ #include <cstdio> #include <iostream> #includ ...

  7. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  8. 水题 Codeforces Round #306 (Div. 2) A. Two Substrings

    题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...

  9. 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table

    题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...

随机推荐

  1. Java8新特性(一)概览

    最近看了好几段Java代码和以往的风格很不一样,都有点不太适应了,后来一查原来是Java8的新特性. 为了保持对技术的敏感性(面试...),这里我们一起来学习下Java8的新特性. 如果从技术角度来看 ...

  2. centos编译 Compiling FFmpeg on CentOS RHEL Fedora

    This guide is based on a minimal installation of the latest CentOS release, and will provide a local ...

  3. EasyDarwin幼教云视频平台在幼教平台领域大放异彩!

    在之前的一篇方案<基于EasyDarwin云视频平台的幼儿园视频直播(手机直播/微信直播)解决方案>中,我们提到一种可以广泛应用于幼教.工厂.建筑工地以及各种现场监控的云视频平台方案,这种 ...

  4. Extjs-树 Ext.tree.TreePanel 动态加载数据

    先上效果图 1.说明Ext.tree.Panel 控件是树形控件,大家知道树形结构在软件开发过程中的应用是很广泛的,树形控件的数据有本地数据.服务器端返回的数据两种.对于本地数据的加载,在extjs的 ...

  5. error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

    1 这个error是什么原因造成的 cmake默认选择的是x86,即32位的生成子. 2 怎么解决这个error 在cmake ..的时候,在后面加上“-G "Visual Studio 1 ...

  6. MongoDB 学习三

    这章我们学习MongoDB的查询操作. Introduction to find find方法用于执行MongoDB的查询操作.它返回collecion中的documents子集,没有添加参数的话它将 ...

  7. 2018年东北农业大学春季校赛 D wyh的迷宫 【BFS】

    题目链接 https://www.nowcoder.com/acm/contest/93/D 思路 BFS模板题 AC代码 #include <cstdio> #include <c ...

  8. RobotFramework教程使用笔记——RIDE的相关知识及Resources创建关键字文件

    RIDE是robotframework的图形操作前端,我们在RIDE上进行测试用例设计和编写测试脚本,并执行自动化测试.下面来全面的认识下这个操作工具. 在右边编辑页面有三大模块,Edit,TextE ...

  9. Window 64位下的客户机配置PLSQL链接远程Oracle

    此文章记录的是艰难探索. 完成如下工作: 服务器A为Windows Serve 2016:安装Oracle. 客户机B为Win7 x64位,安装PLSQLDevelop,链接A上的Oracle. 首先 ...

  10. 配置maven环境变量并安装jar包到本地仓库

    1.下载maven安装包,解压,解压目录如下: 2.配置M2_HOME变量为上一步的路径: 3.配置PATH变量,添加%M2_HOME%\bin;  查看是否配置成功 mvn -v : 4.安装jar ...