过了这么久才来写……

  BC的后两道题好难……(第二道题也不怎么简单……)

1001 Fxx and string

  正着倒着枚举一次就ok

  

#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 10005
char a[N];
int main() {
int T,len,ans;
scanf("%d",&T);
while(T--) {
scanf("%s",a+);
len = strlen(a+);
ans = ;
for(int i = ;i <= len;i++){
if(a[i] != 'y') continue;
for(int k = ;true;k++){
if(i*k*k > len) break;
if(a[i*k]=='r' && a[i*k*k]=='x') ans++;
}
}
for(int i = ;i <= len;i++){
if(a[i] != 'x') continue;
for(int k = ;true;k++){
if(i*k*k > len) break;
if(a[i*k]=='r' && a[i*k*k]=='y') ans++;
}
}
printf("%d\n",ans);
}
return ;
}

  这个题更新数据以后,爆搜肯定挂,比如(1000000,1,100000)

  所以要用dp,dp[x] = min(dp[x-i],dp[x/k]) ,1<=i<=t,容易想明白,但是暴力转移肯定挂,至于线段树,我帮你们写了,也挂……

  所以只能维护单调队列来优化这个dp

  维护[x-t,x-1]之间的单调队列,使其从队头到队尾是递增的,然后正常转移,更新单调队列就可以(单调队列在dp里的用处真的很大)

  单调队列代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<deque>
using namespace std;
const int INF = 1e9;
const int N = 1e6+;
int dp[N],n,k,t;
deque<int> dq; ///维护一个从队尾到队头 递减的队列
int main() {
int T,x;
scanf("%d",&T);
while(T--) {
scanf("%d%d%d",&n,&k,&t);
dp[]=;
while(!dq.empty()) dq.pop_back();
dq.push_back();
for(int i=; i<=n; i++) {
dp[i]=INF;
if(i%k==) dp[i]=min(dp[i],dp[i/k]+);
while(!dq.empty()) {
x=dq.front();
if(x<i-t||x>i-) dq.pop_front();
else break;
}
if(!dq.empty()) dp[i]=min(dp[i],dp[x]+);
while(!dq.empty()) {
x=dq.back();
if(dp[x]>=dp[i]) {
dq.pop_back();
} else break;
}
dq.push_back(i);
}
printf("%d\n",dp[n]);
}
return ;
}

  挂了的线段树代码(笑哭)

#include<iostream>
#include<cstdio>
#include<map>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e6+;
#define lc 2*node
#define rc 2*node+1
#define MAX 1e9
int seg[N*+],dp[N];
void Build(int node,int l,int r){
if(l == r) seg[node] = MAX;
else {
int mid = (l+r)>>;
Build(lc,l,mid);
Build(rc,mid+,r);
seg[node] = min(seg[lc],seg[rc]);
}
}
void Update(int node,int l,int r,int k,int num){
if(l==r) {
seg[node] = num;
return;
}
int mid = (l+r)>>;
if(k <= mid) Update(lc,l,mid,k,num);
else Update(rc,mid+,r,k,num);
seg[node] = min(seg[lc],seg[rc]);
}
int query(int node,int l,int r,int ql,int qr){
int p1,p2;
if(ql > r || qr < l) return MAX;
if(l >= ql && r <= qr) return seg[node];
int mid = (l+r)>>;
p1 = query(lc,l,mid,ql,qr);
p2 = query(rc,mid+,r,ql,qr);
return min(p1,p2);
}
int main()
{
int T,x,k,t;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&x,&k,&t);
Build(,,x);
dp[] = ;
Update(,,x,,dp[]);
for(int i = ;i <= x;i++){
int q = query(,,x,i-t,i-);
dp[i] = q+;
if(i % k == ) dp[i] = min(dp[i],dp[i/k]+);
Update(,,x,i,dp[i]);
}
printf("%d\n",dp[x]);
}
return ;
}

BestCoder Round #89的更多相关文章

  1. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  2. BestCoder Round #89 B题---Fxx and game(单调队列)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5945     问题描述 输入描述 输出描述 输入样例 输出样例 题意:中文题,不再赘述: 思路:  B ...

  3. HDU 5945 / BestCoder Round #89 1002 Fxx and game 单调队列优化DP

    Fxx and game 问题描述   青年理论计算机科学家Fxx给的学生设计了一款数字游戏. 一开始你将会得到一个数\:XX,每次游戏将给定两个参数\:k,tk,t, 任意时刻你可以对你的数执行下面 ...

  4. BestCoder Round #89 Fxx and string

    问题描述 青年理论计算机科学家Fxx得到了一个只包含小写字母的字符串. 字符串的长度为\:nn,下标从1开始,第\:i\:i位的字母为\:s_is​i​​,现在Fxx想知道有多少三元组\:(i,j,k ...

  5. BestCoder Round #89 1002 Fxx and game

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5945 分析: 很容易想到用bfs,然而会超时,几乎是O(xt)了 这里用单调队列优化, 首先反着来,f ...

  6. BestCoder Round #89 1001 Fxx and string

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5944 分析: 竟然 i,j,k成等比数列,即i*k = j*j,还要满足 j|i or j|k. 不防 ...

  7. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  8. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  9. Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

随机推荐

  1. docker的网络-Container network interface(CNI)与Container network model(CNM)

    Overview 目前围绕着docker的网络,目前有两种比较主流的声音,docker主导的Container network model(CNM)和社区主导的Container network in ...

  2. 关于ASP.NET WebAPI中HTTP模型的相关思考

    对于.NET的分布式应用开发,可以供我们选择的技术和框架比较多,例如webservice,.net remoting,MSMQ,WCF等等技术.对于这些技术很多人都不会陌生,即时没有深入的了解,但是肯 ...

  3. 获取Exception的详细信息

    转自:http://blog.csdn.net/long95wang/article/details/8089489 方法一: public static String getExceptionAll ...

  4. java访问权限的问题

    java访问权限的问题 java 访问权限 修饰符 背景: 关于java中的四种访问修饰符,public ,default ,protected ,private的作用范围本以为很熟悉了,但碰到了这样 ...

  5. 【转】Oracle + PHP Cookbook(php oracle clob 长度超过4000如何写入)

      在甲骨文LOB和PHP工作 由哈里Fuecks 达到4,000字节的限制?输入LOB ... 在这个"Oracle + PHP Cookbook"HowTo中,您将学习可用的L ...

  6. Python 自动给数字前面补0

    为了排版方便或者是输出文件命名整洁,通常需要给数字前面补0来做统一.Python中有一个zfill函数用来给字符串前面补0,非常有用,这个zfill看起来也就是zero fill的缩写吧,看一下如何使 ...

  7. python3.5 修改 IIS WEB.CONFIG的相关方法

    #!/usr/bin/env python3.5 # -*- coding:utf8 -*- from xml.etree.ElementTree import ElementTree,Element ...

  8. metrics实践 (metrics-spring)

    这里主要介绍metrics与spring集成的使用方式. 1  添加maven依赖 <dependency> <groupId>com.ryantenney.metrics&l ...

  9. Linux下重置MySQL的Root帐号密码

    1.停止MySQL服务 /etc/init.d/mysqld stop 2.跳过验证启动MySQL /usr/local/mysql/bin/mysqld_safe --skip-grant-tabl ...

  10. HDU 5868 Different Circle Permutation

    公式,矩阵快速幂,欧拉函数,乘法逆元. $an{s_n} = \frac{1}{n}\sum\limits_{d|n} {\left[ {phi(\frac{n}{d})×\left( {fib(d ...