BestCoder Round #89
来源:互联网 发布:电脑屏幕录像软件 编辑:程序博客网 时间:2024/06/01 09:47
这次BC大家好像都比较反感,哎,其实没必要计较太多的,小渣个人觉得还好,过了两题,所以写下博客,总结一下,以免到时候忘了
1001.Fxx and string
题目意思非常简单,就是给个字符串找出三个下标满足等比数列的字符,第一个字符为
BC官方题解
枚举
代码
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int MAXN = 1e4 + 5;char S[MAXN];int main(){ int _; scanf("%d", &_); while(_ --){ scanf("%s", S + 1); int len = strlen(S + 1); LL ans = 0; for(int i = 1;i <= len;i ++){ for(int j = 1; i * i * j <= len;j ++){ if(S[j] == 'y' && S[i * j] == 'r' && S[i * j * i] == 'x') ans ++; if(S[j] == 'x' && S[i * j] == 'r' && S[i * j * i] == 'y') ans ++; } } printf("%I64d\n", ans); } return 0;}
1002.Fxx and game
这道题目求解的是
X=X−i(1<=i<=t) - 若
X 为k 的倍数,X=Xk
这里直接列出状态转移方程:
通过观察我们发现,得到
官方题解
设
用单调队列维护一下就好了
时间复杂度
代码
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;typedef pair<int,int>PII;typedef long long LL;const int MAXN = 1e6 + 5;const int INF = 0x3f3f3f3f;int X, k, t;int dp[MAXN << 1];PII Q[MAXN];int head, tail;int main() { int _; scanf("%d", &_); while(_ --) { scanf("%d%d%d", &X, &k, &t); memset(dp, 0x3f, sizeof(dp)); dp[1] = 0; head = 0, tail = 0; Q[tail ++] = PII(dp[1], 1); for(int i = 2; i <= X; i ++) { while(head < tail && i - Q[head].second > t) head ++; if(head < tail){ dp[i] = Q[head].first + 1; } if(i % k == 0){ dp[i] = min(dp[i], dp[i / k] + 1); } while(head < tail && Q[tail - 1].first > dp[i]) tail --; Q[tail ++] = PII(dp[i], i); } printf("%d\n", dp[X]); } return 0;}
1 0
- BestCoder Round #89
- BestCoder Round #89
- BestCoder Round #89
- BestCoder Round #89
- BestCoder Round #89题解报告
- BestCoder Round #89 1001 Fxx and string
- [BestCoder Round #89]Fxx and tree
- 【枚举】HDU5944Fxx and string【BestCoder Round #89】
- BestCoder Round #3 BestCoder Sequence
- bestcoder round #1
- BestCoder round #1
- BestCoder Round #1
- 【索引】BestCoder Round #2
- BestCoder Round #2
- 【索引】BestCoder Round #3
- BestCoder Round #3
- BestCoder Round #3 小记
- BestCoder Round #4 题解
- 【C++】【啊哈!算法】第四章 万能的搜索
- 手机助手(五):模块化开发 + nineOldAndroid.jar
- 星期六
- 深度学习-受限玻尔兹曼机(RBM)
- addEventListener()和attachEvent()跨浏览器的兼容性处理 — 第13.2.5节
- BestCoder Round #89
- BestCoder Round #89
- mybatis 与 hibernate 的区别和应用场景(转)
- Swift3.0 二维码扫描
- C rand 和 srand 函数
- JAVA跨越加个过滤解决
- Python--面向对象
- python ucs-2与ucs-4编码方式判断
- 洛谷1710 地铁涨价