POJ3274
来源:互联网 发布:淘宝客自动赚钱软件 编辑:程序博客网 时间:2024/05/01 16:43
这个题也是数组hash,不过很巧妙,先开始看不出来。
后来看了别人的解题才知道。强烈推荐
后来看了别人的解题才知道。强烈推荐
code:
#include <iostream>#include <cstdio>#include <string>#include <algorithm>using namespace std;#define mod 999983struct hash{ int d; hash* next; hash(){next = NULL;}}*h[1000000];int n,k;int f[100010][32];int ans = 0;int key;int get_key(int x){ int key = 0; for(int i=0;i<k-1;i++) key += f[x][i]%mod; return (key+mod)%mod;}void insert(int x){ bool ret = false; if(!h[key]) { h[key] = new hash; h[key]->d = 0; h[key]->next = new hash; h[key]->next->d = x; return ; } hash *temp = h[key]; while(temp->next) { temp = temp->next; int r = temp->d; int flag = 1; for(int i=0;i<k-1;i++) if(f[x][i]!=f[r][i]){flag = 0;break;} if(flag){ans = max(ans,x-r);ret = true;} } if(!ret) { temp->next = new hash; temp = temp->next; temp->d = x; }}int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d%d",&n,&k)) { memset(h,0,sizeof(h)); ans = 0; for(int i=0;i<k;i++) f[0][i] = 0; for(int i=1;i<=n;i++) { int t; scanf("%d",&t); for(int j=0;j<k;j++) f[i][j] = f[i-1][j] + ((t>>j) & 1); } key = 0; insert(0); for(int i=1;i<=n;i++) { for(int j=0;j<k-1;j++) f[i][j] = f[i][j+1] - f[i][j]; //for(int j=0;j<k-1;j++) // cout << f[i][j] <<" "; //cout << endl; key = get_key(i); insert(i); } printf("%d\n",ans); } return 0;}
- POJ3274
- poj3274
- poj3274
- poj3274
- poj3274
- poj3274
- POJ3274
- poj3274
- poj3274 hash
- poj3274 hash
- Gold Balanced Lineup poj3274
- POJ3274 Gold Balanced Lineup
- poj3274 hash数组
- poj3274数位HASH
- poj3274 Gold Balanced Lineup
- [POJ3274]-Gold Balanced Lineup
- [POJ3274] Gold Balanced Lineup
- poj3274(数字hash)
- Hive安装配置
- UIViewController使用属性modalPresentationStyle
- 在Chrome OS 上看到一些价值
- 图片浮动
- OpenGL中gl,glu,glut的区别
- POJ3274
- Linux Shell脚本编程基础
- Log4net开源组件的用法心得
- boost::flyweight使用
- 关于Codeblocks中的编译器问题
- 使用GPRS模块进行TCP/UDP连接的问题
- 一个Testng的测试例子
- 关于微软鼠标和键盘中心安装报错1603的解决方法
- C语言-字符串比较