Codeforces 813 B The Golden Age
2017-06-06 17:13
375 查看
题目地址: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])。(详细请看代码)
题意:就是告诉你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 0x3f3f3f3f using namespace std; LL a , b ; 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 << end becb l; } return 0; }
相关文章推荐
- The golden age of the developer
- The golden age of the developer
- Educational Codeforces Round 22-B. The Golden Age-暴力枚举+map
- The Golden Age CodeForces - 813B
- B.The Golden Age
- B. The Golden Age——math
- codeforces round 22 B.The Golden Age(枚举)
- Why The Golden Age Of Machine Learning is Just Beginning
- CF813B:The Golden Age(数学)
- Codeforces 813 C The Tag Game
- B. The Golden Age
- Educational Codeforces Round 22 B. The Golden Age(枚举)
- 【数学】codeforces B. The Golden Age
- 【Codeforces 903B】The Modcrab
- 【CodeForces】A. I Wanna Be the Guy
- (CodeForces 883A) The Meaningless Game 纯正的数学思维题(有点卡cin时间)
- Codeforces 2016 ACM Amman Collegiate Programming Contest B. The Little Match Girl(贪心)
- codeforces 598D - Igor In the Museum
- Codeforces 834B-The Festive Evening
- codeforces 834C (The Meaningless Game)