Codeforces 813 B The Golden Age
来源:互联网 发布:南风知我意结局是什么 编辑:程序博客网 时间:2024/06/05 04:44
题目地址:http://codeforces.com/contest/813/problem/B
题意:就是告诉你x,y两个值,让你通过 n = x^a + y^b,求出的n就是不幸运数,让你求出l~r范围内幸运数连续的最长区间是多少。
思路:就是把在l~r范围内的全部的不幸运数求出来,记录下来。求最长的区间长度就是把全部不幸运数排序,再现在在这个数组里相邻的两个不幸运数相减再减一就是区间长度,但是l和r这两个区间端点需要特判,就是max(v[0] - l, r - v[v.size() - 1])。(详细请看代码)
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <algorithm>#define N 110#define LL long long #define inf 0x3f3f3f3fusing namespace std;LL a[N], b[N];vector<LL> v;int main() { cin.sync_with_stdio(false); LL x, y, l, r; LL lena, lenb; while (cin >> x >> y >> l >> r) { a[0] = 1; b[0] = 1; lena = 1; lenb = 1; while (r/x>=a[lena-1]){ a[lena] = a[lena - 1] * x; lena++; } while (r / y >= b[lenb - 1]) { b[lenb] = b[lenb - 1] * y; lenb++; } v.clear(); for (int i = 0; i < lena; i++) { for (int j = 0; j < lenb; j++) { if (a[i] + b[j] >= l) { if (a[i] + b[j] > r) { break; } v.push_back(a[i] + b[j]); } } } sort(v.begin(), v.end()); LL ans = 0; if (!v.size()) { ans = r - l + 1; } else { ans = max(v[0] - l, r - v[v.size() - 1]); } for (int i = 0; i < v.size(); i++) { ans = max(ans, v[i] - l - 1); l = v[i]; } cout << ans << endl; } return 0;}
阅读全文
0 0
- CodeForces 813B The Golden Age
- Codeforces 813 B The Golden Age
- Codeforces 813B The Golden Age 题解
- CodeForces 813B The Golden Age
- codeforces round 22-B.the golden age
- The Golden Age CodeForces
- B. The Golden Age
- B.The Golden Age
- Educational Codeforces Round 22 B. The Golden Age(枚举)
- codeforces round 22 B.The Golden Age(枚举)
- B. The Golden Age——math
- Educational Codeforces Round 22-B. The Golden Age-暴力枚举+map
- The golden age of the developer
- The golden age of the developer
- CF813B:The Golden Age(数学)
- 《Golden Age》 --- 黄金时代
- The golden award
- China Is Poised for an I.T. Golden Age
- nginx简易教程
- 天生爱表演的ESFP职业规划和天赋解析
- soap的命名空间
- python+Selenium2+chrome构建浏览器模拟环境
- 268. Missing Number
- Codeforces 813 B The Golden Age
- UE4.17将正式支持ARKit
- 利用Windows服务器发布网站
- 本地项目上传git远程仓库
- tableview二级联动
- 总结三
- 128. Longest Consecutive Sequence
- 内存
- 动态规划略有所得 数字三角形(POJ1163)