(水题)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> ...
 
随机推荐
- Apache/Nigix + Tomcat + 负载均衡
			
Part I: Apache + Tomcat + 负载均衡 http://www.open-open.com/lib/view/open1350612892352.html http://micha ...
 - C++ 坑人系列(1): 让面试官晕倒的题目
			
今天和几位同仁一起探讨了一下C++的一些基础知识,在座的同仁都是行家了,有的多次当过C++技术面试官.不过我出的题过于刁钻: 不是看起来太难,而是看起来极其容易,但是其实非常难! 结果一圈下来,3道 ...
 - 深入理解Java:注解(Annotation)自己定义注解入门
			
深入理解Java:注解(Annotation)自己定义注解入门 要深入学习注解.我们就必须能定义自己的注解,并使用注解,在定义自己的注解之前.我们就必须要了解Java为我们提供的元注解和相关定义注解的 ...
 - java socket InputStream和OutputStream
			
从java socket对象获取的InputSteam的read方法其实是对linux的recv()函数的调用,OutputStream也同理. 也就是说,InputStream和OutputStre ...
 - cerery
			
cerery http://docs.celeryproject.org/en/latest/userguide/index.html
 - Ubuntu Firefox没有声音的解决方案
			
安装ubuntu-restricted-extras sudo apt-get install ubuntu-restricted-extras 参考博文:解决ubuntu中firefox没有声音的问 ...
 - js复杂数据格式提交
			
有的时候额后台需要一个对象Map值,如{name: '姓名',attributeMap:{skill: '名称;checkbox;true;&篮球:1,羽毛球:2',name:'lsg' }} ...
 - AndroidContactsTest.java
			
以下代码使用ContactManager.apk进行测试 package com.saucelabs.appium; import io.appium.java_client.AppiumDriver ...
 - apache配置文件详解及虚拟主机的搭建
			
1.404跳转: <IfModule dir_module> DirectoryIndex index.php index.html /error.php</IfModule& ...
 - wifi方式调试android程序
			
1. 通过wifi, 利用adb来连接手机. 在pc的cmd中输入命令: adb connect 192.168.1.100 其中adb就是手机的ip. 如果连接成功, 就可以进入android的sh ...