http://acm.hdu.edu.cn/search.php?field=problem&key=BestCoder+Round+%2389&source=1&searchmode=source
http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=730
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1001 HDU5944 Fxx and string
题意:
题解:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define de(x) cout << #x << "=" << x << endl
const int N=10005;
char s[N];
int main() {
int T;scanf("%d",&T);
while(T--) {
scanf("%s",s+1);
int n=strlen(s+1);
int ans=0;
for(int i=1;i<=n;++i) {
if(s[i]!='y') continue;
for(int j=2;i*j*j<=n;++j) {
if(s[i*j]=='r'&&s[i*j*j]=='x') ++ans;
}
}
for(int i=1;i<=n;++i) {
if(s[i]!='x') continue;
for(int j=2;i*j*j<=n;++j) {
if(s[i*j]=='r'&&s[i*j*j]=='y') ++ans;
}
}
printf("%d\n",ans);
}
return 0;
}<strong>
</strong>
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
题解:d[i]=min(d[j],d[i/k])+1 (0<=j<=t) 直接转移复杂度是x*t。可以用单调队列存d[j]。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define de(x) cout << #x << "=" << x << endl
const int N=1000005;
int d[N],q[N],ti[N];
int x,k,t;
int main() {
int T;scanf("%d",&T);
while(T--) {
scanf("%d%d%d",&x,&k,&t);
d[1]=0;
int l=1,r=1;
q[r]=0;ti[r]=1;//首先把d[1]放进去
for(int i=2;i<=x;++i) {
//不符合的出队
while(l<r&&ti[l]<i-t) ++l;
//设置d[i]
d[i]=q[l];
if(i%k==0) d[i]=min(d[i],d[i/k]);
++d[i];
//d[i]入队
while(l<=r&&q[r]>=d[i]) --r;
q[++r]=d[i];ti[r]=i;
}
printf("%d\n",d[x]);
}
return 0;
}