【HDOJ】1800 Flying to the Mars
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的更多相关文章
- 杭电 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 ...
- HDU 1800——Flying to the Mars——————【字符串哈希】
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDOJ.1800 Flying to the Mars(贪心+map)
Flying to the Mars 点我挑战题目 题意分析 有n个人,每个人都有一定的等级,高等级的人可以教低等级的人骑扫帚,并且他们可以共用一个扫帚,问至少需要几个扫帚. 这道题与最少拦截系统有异 ...
- hdu 1800 Flying to the Mars
Flying to the Mars 题意:找出题给的最少的递增序列(严格递增)的个数,其中序列中每个数字不多于30位:序列长度不长于3000: input: 4 (n) 10 20 30 04 ou ...
- HDU - 1800 Flying to the Mars 【贪心】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1800 题意 给出N个人的 level 然后 高的level 的 人 是可以携带 比他低level 的人 ...
- 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 ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- --hdu 1800 Flying to the Mars(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Ac code: #include<stdio.h> #include<std ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
随机推荐
- c++程序开发利器
c++程序开发利器 vc6visual stdio系列都很好,个人最喜欢vc6,主要原因是快捷,classview和wizardbar功能强大,其他vs秒杀其他的vs windbgWinDbg是在wi ...
- php开发过程中用什么方法来加快页面的加载速度
1,数据库优化;2,php缓存;3,使用zend引擎(其它框架);4,分布式部署;5,静态
- hbase meta表修复
meta表修复一 查看hbasemeta情况hbase hbck1.重新修复hbase meta表(根据hdfs上的regioninfo文件,生成meta表)hbase hbck -fixMeta2. ...
- linux 命令小结
chkconfig --list 查询所有服务运行情况 修改文件夹权限: 在Linux中,权限的所有者分为用户权限,组权限和其他权限,分别是用字母u, g, o 代表权限分为:读 r , 写 w , ...
- struts2传map到前台出现的问题
后台打印出的错: 2016-08-16 13:42:52.652 WARN org.apache.struts2.json.JSONWriter - JavaScript doesn't s ...
- javaee web项目的目录结构
一般web系统的目录结构如下,其中src下的包结构和webroot下(除meta-inf和web-inf)的文件夹可以根据自己的项目实际调整,但是javaee规范的大目录结构不会变: META-INF ...
- IIS7.5 自定义Html/shtml/htm...后缀映射
以添加html后缀的文件的 映射为例: 1.打开iis管理器,点击 2.点击打开处理程序映射 3.添加托管处理程序映射 4.请求路径 *.html 类型: System.Web.UI.PageHand ...
- python正则表达式——re模块
http://blog.csdn.net/zm2714/article/details/8016323 re模块 开始使用re Python通过re模块提供对正则表达式的支持.使用re的一般步骤是先将 ...
- Linq to Entity中连接两个数据库时要注意的问题
Linq to Entity中连接两个数据库时要注意的问题 今天大学同学问了我一个问题,Linq to Entity中连接两个数据库时,报错“指定的 LINQ 表达式包含对与不同上下文关联的查询的引用 ...
- 【redis】03list类型
list类型 redis的list类型是一个链表结构,他的主要功能是push.pop.获取一个范围的所有值等等一些操作, 咱们push什么意思,push是不是相当于咱们php里面的array_push ...