(水题)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> ...
随机推荐
- SharePoint ULS Log Viewer 日志查看器
SharePoint ULS Log Viewer 日志查看器 项目描写叙述 这是一个Windows应用程序,更加轻松方便查看SharePoint ULS日志文件.支持筛选和简单的视图. 信息 这是一 ...
- 2018.11.23-day27 面向对象(大总结)
1. 2个内置函数 2.反射 3.内置方法 4.面向对象大总结 思维导图地址:https://www.processon.com/view/link/5bfcfd62e4b0ef094cbf04a7 ...
- 图片转base64存储
图片转base64存储 base64.b64encode(r.content) url='http://www.heze.cn/info/themes/heze/Public/tel/?tel=MDU ...
- 小程序 富文本 的页面展示 json 数据处理 go-echo 为小程序提供feed流服务
go生成页面 返回给web-view {{define "DBHtmlCode"}} <!DOCTYPE html> <html lang="zh-cm ...
- 最简单的 IntelliJ IDEA 中使用 GitHub 进行版本控制教程(持续更新中)
一.在 IntelliJ IDEA 中新建一个项目并提交到 GitHub 1. 运行 IDEA,点击[Create New Project],在 IDEA 中新建一个项目. 2. 在选择项目类型对话框 ...
- ZOJ - 3953 Intervals 【贪心】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3953 题意 给出N个区间,求去掉某些区间,使得剩下的区间中,任何 ...
- Java WebService一个构建
参考:http://dyygusi.iteye.com/blog/2148029 下面是自己的实践路线,
- spring+mybatis项目整合
前辈总结的很详细,贴出链接,参考学习 http://www.open-open.com/lib/view/open1392252233301.html
- UVA12293 Box Game —— SG博弈
题目链接:https://vjudge.net/problem/UVA-12293 题意: 两人玩游戏,有两个盒子,开始时第一个盒子装了n个球, 第二个盒子装了一个球.每次操作都将刷量少的盒子的球倒掉 ...
- IOS开发学习笔记(2)-----UIButton 详解
1. [代码][C/C++]代码 //这里创建一个圆角矩形的按钮 UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRou ...