HDU 6103 Kirinriki(思维尺取)
2017-10-04 20:11
411 查看
题意:在一个字符串中,选取两个长度相同且不重合的子串,计算dis值,定义为abcde efcgh 的a~h+b~g+c~c+d~f..即计算对应位置的差值和.
给定m,找到满足dis值小于等于m的最大子串对长度.
关键:枚举对称轴.进行尺取
复杂度 O(m^2).m<=5000
事实上,在见到小于等于m的时候,要想到尺取,对应位置差值和,应想到枚举对称轴.处理时注意可能对称到空处,*2后分奇偶讨论.
给定m,找到满足dis值小于等于m的最大子串对长度.
关键:枚举对称轴.进行尺取
复杂度 O(m^2).m<=5000
事实上,在见到小于等于m的时候,要想到尺取,对应位置差值和,应想到枚举对称轴.处理时注意可能对称到空处,*2后分奇偶讨论.
/* xzppp */ #include <iostream> #include <vector> #include <cstdio> #include <string.h> #include <algorithm> #include <queue> #include <map> #include <string> #include <cmath> #include <bitset> #include <iomanip> using namespace std; #define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define MP make_pair #define PB push_back #define _ %MOD typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int > pii; typedef pair<LL,LL> pll; typedef pair<double,double > pdd; typedef pair<double,int > pdi; const int MAXM = 2e3+17; const int MAXV = 2*1e3+17; const int BIT = 15+3; const int INF = 0x7fffffff; const LL INFF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9+7; const int MAXN = 1e5+17; string str; int main() { #ifdef GoodbyeMonkeyKing FFF #endif int t,x; cin>>t; x = t; while(t--) { int m; cin>>m>>str; int ans = 0; for (int i = 1; i < 2*str.length(); ++i) { int l = i/2-1,r=i/2+1; if(i&1) l++; int temp = 0,lth = 0; queue<int > q; while(l>-1&&r<str.length()) { q.push(abs(str[r]-str[l])); temp += abs(str[r]-str[l]); lth++; if(temp>m&&!q.empty()) { temp -= q.front(); q.pop(); lth--; } ans = max(lth,ans); l--;r++; } } cout<<ans<<endl; } return 0; }
相关文章推荐
- HDU 6103 Kirinriki【尺取法】【思维题】【好题】
- HDU 6103 Kirinriki (思维 双指针)
- HDU - 6103 Kirinriki(字符串匹配+思维)
- HDU 6103 Kirinriki(尺取法 思维)
- hdu 6103 Kirinriki(多校联赛)
- hdu 6103 Kirinriki 尺取
- HDU 6103 17多校6 Kirinriki(双指针维护)
- hdu 6103 Kirinriki
- Kirinriki(HDU 6103)
- hdu--6103--Kirinriki
- 2017 Multi-University Training Contest - Team 6 HDU 6103 Kirinriki (尺取法)
- hdu 6103(Kirinriki)
- hdu 6103 Kirinriki(尺取法)
- HDU_6103 Kirinriki 【尺取法】
- hdu 6103 Kirinriki 尺取
- HDU 2017 多校联合训练赛6 1008 6103 Kirinriki 优美的暴力
- HDU 6103 Kirinriki
- 多校6 HDU-6103 Kirinriki 双指针
- hdu 6103 Kirinriki 尺取
- HDU 6103 Kirinriki