(水题)Codeforces - 4C - Registration system
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的更多相关文章
- 水题 Codeforces Round #302 (Div. 2) A Set of Strings
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...
- 水题 Codeforces Round #300 A Cutting Banner
题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...
- 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas
题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...
- 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...
- 水题 Codeforces Round #303 (Div. 2) A. Toy Cars
题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...
- 水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift
题目传送门 /* 水题:vector容器实现插入操作,暴力进行判断是否为回文串 */ #include <cstdio> #include <iostream> #includ ...
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...
- 水题 Codeforces Round #306 (Div. 2) A. Two Substrings
题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...
- 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table
题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...
随机推荐
- Discuz系列1:安装
http://www.discuz.net/forum.php 官网,点击“Discuz! 程序发布” 代码库: https://git.oschina.net/ComsenzDiscuz/D ...
- multiTarget within one project pods manage
step1:file->new->target create 1 targetstep2:change Podfile and update podstep3:check new targ ...
- objective-c中#import和@class的差别
在Objective-C中,能够使用#import和@class来引用别的类型, 可是你知道两者有什么差别吗? @class叫做forward-class, 你常常会在头文件的定义中看到通过@cla ...
- EasyDarwin开源流媒体服务器进行RTSP转发过程中将sdp由文件存储改成内存索引
-本篇由团队成员Fantasy供稿! 原始版本 在Darwin Streaming Server版本中,推送端DoAnnounce的时候后服务器会根据easydarwin.xml中配置的movies_ ...
- Hibernate基础知识介绍
一.什么是Hibernate? Hibernate,翻译过来是冬眠的意思,其实对于对象来说就是持久化.持久化(Persistence),即把数据(如内存中的对象)保存到可永久保存的存储设备中(如磁盘) ...
- checkbox 背景图片 纯CSS处理办法
CSS .table_container input[type="checkbox"] { background: #fff url(/img/blue.png); backgro ...
- var与变量提升
var是否可以省略 一般情况下,是可以省略var的,但有两点值得注意: 1.var a=1 与 a=1 ,这两条语句一般情况下作用是一样的.但是前者不能用delete删除.不过,绝大多数情况下,这种差 ...
- SQL 关联操作
- Could not find com.android.tools.lint:lint-gradle:26.1.2.
allprojects { repositories { flatDir { dirs 'libs' } jcenter() google() }}
- PAT 天梯赛 L1-050. 倒数第N个字符串 【字符串】
题目链接 https://www.patest.cn/contests/gplt/L1-050 思路 因为是求倒数 我们不如直接 倒过来看 令 zzz 为第一个字符串 我们可以理解为 十进制 转换为 ...