1. 题目描述
挺简单的一道题,给定$n$个大整数,求出现最多的次数。

2. 基本思路
这题是可以使用哈希做,ELFHash等哈希都可以过。

3. 代码

 /* 1800 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxl = ;
const int MOD = ;
int H[MOD], cnt[MOD];
char s[maxl];
int n, ans; inline int ELFHash(char *s) {
unsigned int h = ;
unsigned int g;
int i = ; while (s[i]) {
h = (h<<) + s[i];
g = h & 0xf0000000L;
if (g) {
h ^= (g >> );
h &= ~g;
}
++i;
} return h & 0x7fffffff;
} inline void Hash(char *s) {
int i = ; while (s[i]=='') ++i;
int k = ELFHash(s+i);
int t = k % MOD; while (H[t]!=- && H[t]!=k)
t = (t + ) % MOD; if (H[t] == -) {
cnt[t] = ;
H[t] = k;
} else if (++cnt[t] > ans) {
ans = cnt[t];
}
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif while (scanf("%d",&n)!=EOF) {
memset(H, -, sizeof(H));
ans = ;
rep(i, , n) {
scanf("%s", s);
Hash(s);
}
printf("%d\n", ans);
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】1800 Flying to the Mars的更多相关文章

  1. 杭电 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 ...

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

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

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

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

  4. hdu 1800 Flying to the Mars

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

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

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

  6. 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 ...

  7. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

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

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

  9. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

随机推荐

  1. 【js】正则表达式豁然开朗

    http://www.jikexueyuan.com/course/809_3.html?ss=1 小括号,中括号 中括号:[] ,它表示里面的字符任选一个 比如[abcd]+,就表示abcd这四个字 ...

  2. iOS应用的真机调试

    必须条件:99美元的帐号,没有这个就不用再往下看了. 首先,登录到http://developer.apple.com/devcenter/ios/index.action,如果已经购买了iPhone ...

  3. dom4j增删改查

    //dom4j添加内容,在第一本书上指定位置添加售价 更改保存所有孩子list集合的顺序 @Test public void add1() throws Exception{ //读 SAXReade ...

  4. ASP.NET Web - 回送

    如果希望把更改事件立即传送给服务器,可以把AutoPostback属性设置为true.这样就会使用客户端的JavaScript把窗体数据立即提交给服务器.当然,网络通信量也会增加.使用这个功能时要小心 ...

  5. Could not locate device support files.《This iPhone 5 (Model A1429) is running iOS 7.0.4 (11B554a), which may not be supported by this version of Xcode.》-b

    原因:Xcode8 不支持 iOS7 解决方法: 在“/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/De ...

  6. WPF 多线程处理(6)

    WPF 多线程处理(1) WPF 多线程处理(2) WPF 多线程处理(3) WPF 多线程处理(4) WPF 多线程处理(5) WPF 多线程处理(6) 以下是子窗体的UI: <Window ...

  7. HTML5网页制作教程:HTML5块级链接

    网页制作Webjx文章简介:Web 标准中处处充满了打脸行为,这条规则现在已经失效了!在那篇文章发布一个月后,HTML5doctor 发表了 “Block-level” links in HTML5, ...

  8. 无废话网页重构系列——(7)布局(区块、栅格)、模块组件(module)

    本文作者:大象本文地址:http://www.cnblogs.com/daxiang/p/4654800.html 在构建HTML主干结构后,开始编写“页面布局”和“模块组件”: 页面框架由几个主干结 ...

  9. Java Servlet Filter(转)

    做web开发的人对于Filter应该不会陌生,一直在很简单的使用,但是一直没有系统的总结一下,随着年纪的慢慢长大,喜欢总结一些事情,下面说说我对Filter的理解,官方给出的Filter的定义是在请求 ...

  10. PHP杂记

    SOAP: 感觉是类似于Java中的HttpClient的东西,和curl也有点像. PHPStorm中查看所有的函数结构(Structure):Alt+7 查找方法或类(Symbol Name 函数 ...