不是很懂?

胡乱hash

 #include <set>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=;
int n,k;
struct node{int p,next,a[];}cow[maxn];
int hashHead[maxn],cnt; bool cmp(int a,int b){
for(int i=;i<=k;i++)if(cow[a].a[i]!=cow[b].a[i])return false;
return true;
} int GetHash(int a){
int ans=;
for(int i=; i<=k; i++)ans=(ans*+cow[a].a[i])%maxn;
return ans>?ans:-ans;
} int main() {
scanf("%d%d",&n,&k);
for(int i=; i<=n; i++){
int x;
scanf("%d",&x);
for(int j=; j<=k; j++,x/=)cow[i].a[j]=x%;
}
for(int i=; i<=n; i++)for(int j=; j<=k; j++)cow[i].a[j]+=cow[i-].a[j];
for(int i=; i<=n; i++)for(int j=; j<=k; j++)cow[i].a[j]-=cow[i].a[k];
int ans=;
for(int i=; i<=n; i++){
int hash=GetHash(i),p=;
for(int j=hashHead[hash];j;j=cow[j].next)if(cmp(i,cow[j].p))p=cow[j].p;
if(p)ans=max(ans,i-p);
if(hash==)ans=max(i,ans);//???
cow[++cnt].p=i;
cow[cnt].next=hashHead[hash];
hashHead[hash]=cnt;
}
printf("%d\n",ans);
return ;
}

C++-POJ3274-Gold Balanced Lineup[hash]的更多相关文章

  1. poj3274 Gold Balanced Lineup(HASH)

    Description Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been abl ...

  2. Gold Balanced Lineup(hash)

    http://poj.org/problem?id=3274 ***** #include <stdio.h> #include <iostream> #include < ...

  3. POJ 3274 Gold Balanced Lineup

    Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10924 Accepted: 3244 ...

  4. 哈希-Gold Balanced Lineup 分类: POJ 哈希 2015-08-07 09:04 2人阅读 评论(0) 收藏

    Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13215 Accepted: 3873 ...

  5. 1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列

    1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 510  S ...

  6. POJ 3274:Gold Balanced Lineup 做了两个小时的哈希

    Gold Balanced Lineup Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13540   Accepted:  ...

  7. 洛谷 P1360 [USACO07MAR]Gold Balanced Lineup G (前缀和+思维)

    P1360 [USACO07MAR]Gold Balanced Lineup G (前缀和+思维) 前言 题目链接 本题作为一道Stl练习题来说,还是非常不错的,解决的思维比较巧妙 算是一道不错的题 ...

  8. Gold Balanced Lineup - poj 3274 (hash)

    这题,看到别人的解题报告做出来的,分析: 大概意思就是: 数组sum[i][j]表示从第1到第i头cow属性j的出现次数. 所以题目要求等价为: 求满足 sum[i][0]-sum[j][0]=sum ...

  9. bzoj 1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列——map+hash+转换

    Description N(1<=N<=100000)头牛,一共K(1<=K<=30)种特色, 每头牛有多种特色,用二进制01表示它的特色ID.比如特色ID为13(1101), ...

  10. bzoj 1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列【hash】

    我%&&--&()&%????? 双模hashWA,unsigned long longAC,而且必须判断hash出来的数不能为0???? 我可能学了假的hash 这个 ...

随机推荐

  1. R 拼接结果展示

    学长教的拼接结果展示 哇,R 简直太有魅力了! 晚一点补充

  2. Linux 基础操作命令

    关机和注销 shutdown -h now 立刻关机 shutdown -r now 立刻重启 shutdown -h + 1分钟后关机(重启同样用法) shutdown -h : 11点钟关机(重启 ...

  3. C# 一次循环获取树的两种方法

    第一种方法好些 第二种方法如果中间断开就会成为一级 private static List<Menu> MenuTree() { , ParentId = , Name = "a ...

  4. VPS性能测试shell工具以及锐速安装

    比较熟悉的UnixBench非常耗费资源,需要长时间跑满cpu和IO,很多主机商都深恶痛绝,会做各种限制,其实也代表不了实际使用的业务效果,毕竟真正需要那么多cpu和IO的应用并不多.而网络状况却是大 ...

  5. immutability-helper 用途+使用方法

    1.react 官网文章 2.github地址  

  6. poj2387- Til the Cows Come Home(最短路板子题)

    题目描述 Description Bessie is out in the field and wants to get back to the barn to get as much sleep a ...

  7. 配置hosts快速访问GitHub

    经常要clone github中的一些项目,无奈如果不爬梯子的话速度实在是龟速,经常1k/s,于是搜了下解决方法,改HOSTS大法.Windows下在C:/Windows/system32/drive ...

  8. openlayers 保存当前地图View为图片

    /** * 保存地图为图片工具栏 */function addMapToolSavePicture() { var saveElement = document.createElement('a'); ...

  9. Attention machenism

    from attention mechanism Attention is one component of a network’s architecture, and is in charge of ...

  10. C++——流类库与输入/输出

    I/O流的概念 当程序与外界环境进行信息交换时,存在着两个对象,一个是程序中的对象,另一个是文件对象,流是一种抽象,它负责在数据的生产者和数据的消费者之间建立连接,并管理数据的流动.程序建立一个流对象 ...