UVA 12238 Anti-Rhyme Pairs(hash+二分)
来源:互联网 发布:在线视频转码 知乎 编辑:程序博客网 时间:2024/06/12 20:04
题意:Anti-Rhyme Pairs
分析:将每个串hash直接二分长度即可
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<set>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )const int INF=0x3f3f3f3f;typedef long long LL;const int maxn=1e5+100;const int mod=1e9+7;const int p=1e6+7;vector<int>v[maxn];char str[maxn];int dp_min[maxn][20],a[maxn];int t,n,m,l,r,st,ed;void Hash(int x){ int len=strlen(str); LL ans=0; a[x]=len; for(int i=0;i<len;i++) { ans=(ans*1LL*p+str[i])%mod; v[x].push_back(ans); }}bool ok(int x){ if(x<0) return true; if(v[st][x]!=v[ed][x]) return false; return true;}int main(){ int cas=1; scanf("%d",&t); while(t--) { scanf("%d",&n); getchar(); REPF(i,1,n) { v[i].clear(); gets(str); Hash(i); } scanf("%d",&m); printf("Case %d:\n",cas++); while(m--) { scanf("%d%d",&st,&ed); l=0,r=min(a[st],a[ed]); int ans; while(l<=r) { int mid=(l+r)>>1; if(ok(mid-1)) { ans=mid; l=mid+1; } else r=mid-1; } printf("%d\n",ans); } } return 0;}
0 0
- UVA 12238 Anti-Rhyme Pairs(hash+二分)
- uva12338 Anti-Rhyme Pairs (字符串hash+二分)
- Uva 12338: Anti-Rhyme Pairs(Hash)
- [UVa 12338] Anti-Rhyme Pairs (字符串哈希+二分)
- UVA - 12338 Anti-Rhyme Pairs (哈希)
- uva12338 - Anti-Rhyme Pairs 询问最长公共前缀 HASH+二分
- UVA 12338 Anti-Rhyme Pairs (字符串哈希+二分)
- UVA 12338 Anti-Rhyme Pairs
- Anti-Rhyme Pairs - UVa 12338 哈希
- UVA 12338 - Anti-Rhyme Pairs(后缀数组+RMQ)
- uva 12338 - Anti-Rhyme Pairs(后缀数组+RMQ)
- 每次询问求出两个字符串的最长公共前缀的长度 后缀数组+RMQ+lcp UVA 12338 - Anti-Rhyme Pairs
- UVA12338Anti-Rhyme Pairs(哈希+二分最长前缀)
- UVA - 10029 Edit Step Ladders (二分+hash)
- uva 10391(Hash)
- hdu 5178 pairs(二分,思路)
- hdu 5178 pairs(二分求解)
- [HDU](5178)pairs ---二分查找(查找)
- android 沉浸式布局学习
- C语言堆栈入门——堆和栈的区别
- 网络编程基础
- Robotium API 二次封装
- Java实现定时任务的三种方法
- UVA 12238 Anti-Rhyme Pairs(hash+二分)
- iOS NSDate
- HDU -1879-继续畅通工程
- IE兼容性问题之trim
- iOS NSNumber
- 正则表达式三
- 史上最全的央企控股上市公司一览------央企改革股票
- python代码`if not x:` 和`if x is not None:`和`if not x is None:`使用
- HDU 1800 Flying to the Mars -- 求一组数中出现频率最大的那个数出现的次数