Flying to the Mars

题意:找出题给的最少的递增序列(严格递增)的个数,其中序列中每个数字不多于30位;序列长度不长于3000;
input:
4 (n)
10
20
30
04
output
1

思路:将节目转化为相同数的最多个数即可~~
这时就随便怎么搞了。我是直接用了map(开始不会hash啊…)来找mx;
但是和字符串hash相比,时间性能不好。
之后看了ACdreamers,学习了ELFhash之后发现挺好用的~~下面将讲解一下我对ELFhash的理解。

// 702ms 1808k
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (n);i++)
map<string,int> mp;
int main()
{
ios_base::sync_with_stdio(false);cin.tie();cout.tie();cerr<<"";
int n,i;
while(cin>>n){
mp.clear();
string str;
rep(i,n){
cin>>str;
int j = ;
for(;j < str.size();j++)if(str[j] != '') break;
mp[str.substr(j)]++;
}
int ans = ;
for(auto m : mp){
ans = max(ans , m.second);
}
cout<<ans<<endl;
}
}

ELFhash:
hash要对字符串里面的每一个字符进行运算,之后得到一个”相对”不同的值(因为有冲突);字符有八个字节的,但是里面对高位的四个字节与前一个字符的低的四个字节相加了,低的四个字节填补了h左移空出来的四个字节(不知理解得是否有误,若有误,请指正~)并且里面的位是从0开始的,即当h<<4时开始的0位,现在就是第4位了。里面的hash运算还有就是在h要满的时候(即h的高四位28~31不为0时),下一次再加进字符时,就会直接移走了,但是算法要将这高四位和4~8位的数再做一次XOR运算,应该是使得得到的hash更随机~~(里面0xF0000000L就表示28~31位全是1,其余位为0)

hash::code @ACdreamers

499ms
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (n);i++)
#define MS0(a) memset(a,0,sizeof(a))
const int MOD = ;
int Hash[MOD],cnt[MOD];
unsigned int ELFhash(char *str)//unsigned
{
unsigned int h = ;
unsigned int x;
while(*str){
h = (h << ) + *str++;//与前一个字符的第四位字节相加;
x = h & 0xF0000000L;//x为h的28~31位
if(x){
h ^= x>>;  //高四位和4~8位的数再做一次XOR运算,不然没运算就移走了,可惜~
h &= ~x;  // h清空28~31位(运算完了)
}
}
return h & 0x7FFFFFFF;//返回unsigned,即0x7FFFFFFF为unsigned的二进制全为1
}
int Hashhit(char *str)
{
while(*str == '') str++;
int k = ELFhash(str);
int t = k % MOD;
while(Hash[t] && Hash[t] != k) //解决冲突;
t = (t + )%MOD;
if(Hash[t] == )
Hash[t] = k;
return ++cnt[t];
}
int main()
{
int n;char str[];
while(scanf("%d",&n) == ){
MS0(Hash);MS0(cnt);
int ans = ;
rep(i,n){
scanf("%s",str);
ans = max(ans,Hashhit(str));
}
printf("%d\n",ans);
}
}

hdu 1800 Flying to the Mars的更多相关文章

  1. HDU 1800——Flying to the Mars——————【字符串哈希】

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. --hdu 1800 Flying to the Mars(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Ac code: #include<stdio.h> #include<std ...

  3. HDU - 1800 Flying to the Mars 【贪心】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1800 题意 给出N个人的 level 然后 高的level 的 人 是可以携带 比他低level 的人 ...

  4. HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...

  5. HDU 1800 Flying to the Mars Trie或者hash

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 题目大意: 又是废话连篇 给你一些由数字组成的字符串,判断去掉前导0后那个字符串出现频率最高. 一开始敲h ...

  6. hdu 1800 Flying to the Mars(简单模拟,string,字符串)

    题目 又来了string的基本用法 //less than 30 digits //等级长度甚至是超过了int64,所以要用字符串来模拟,然后注意去掉前导零 //最多重复的个数就是答案 //关于str ...

  7. 杭电 1800 Flying to the Mars(贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/Oth ...

  8. HDOJ.1800 Flying to the Mars(贪心+map)

    Flying to the Mars 点我挑战题目 题意分析 有n个人,每个人都有一定的等级,高等级的人可以教低等级的人骑扫帚,并且他们可以共用一个扫帚,问至少需要几个扫帚. 这道题与最少拦截系统有异 ...

  9. HDOJ 1800 Flying to the Mars 盲目搜索......................so easy...........

    check the original problem here:http://acm.hdu.edu.cn/showproblem.php?pid=1800 the AC code: #include ...

随机推荐

  1. SIGGRAPH

    这两天看了一些文章,今天来说说SIGGRAPH. 对于搞图形学的人来说,SIGGRAPH绝对是如雷贯耳.SIGGRAPH是计算机图形界(也包含图像)最顶级的会议,没有之中的一个,是全世界的图形学者公认 ...

  2. 路冉的JavaScript学习笔记-2015年2月5日

    1.为Js原始值创建临时对象,并进行属性引用 var s="text"; s.len=4;//这里Js调用new String(s)的方法创建了一个临时对象,用来属性引用 cons ...

  3. &lt;Android&gt;从窗口泄漏谈android:configChanges属性

    今天有幸去哥们的大公司做了半天的暂时工,一个偶现的Bug折腾了他好久,好不easy今天抓到了异常Log日志.大致的意思就是android.view.windowleaked--窗口泄漏.我在网上查了资 ...

  4. Kinect开发学习笔记之(一)Kinect介绍和应用

    Kinect开发学习笔记之(一)Kinect介绍和应用 zouxy09@qq.com http://blog.csdn.net/zouxy09 一.Kinect简单介绍 Kinectfor Xbox ...

  5. cocos2d-x jsb + cocosbuider 适配iphone5 尺寸

    最简单的适配iphone5的方案,应该算是直接用一块图片补上多出来的区域了: 1:Iphone5分辨率为 1136* 640 , 需要在cocosbuilder中将ccb修改为对应的尺寸: Docum ...

  6. android103 内容观察者

    #内容观察者 * 通过内容提供者可以访问到数据库,当数据库数据改变时,内容提供者会发出通知,在内容提供者的uri上注册一个内容观察者,就可以收到数据改变的通知,类似于广播接受者,但是他不是广播. cr ...

  7. sort函数的例子

    10.11编写程序,使用stable_sort和isShorter将传递给你的elimDups版本的vector排序.打印vector的内容. #include<algorithm> #i ...

  8. Mac中Eclipse配置Maven开发环境

    1.下载Maven tar.gz包 http://maven.apache.org/download.cgi 2.解压tar包 随便一个路径都行 3.配置环境变量 bash设置~/.bash_prof ...

  9. CSS样式表介绍

    一.    CSS中的样式选择 1)内样式(内联样式) style=””; 2)内嵌样式 <style type="text/css"></style> 3 ...

  10. java- 枚举的常见用法

    用法一:常量 public enum MyColor{Red,Black,Blue} public enum Color { RED, GREEN, BLANK, YELLOW } enum为枚举类的 ...