Codeforces 813B The Golden Age 题解
来源:互联网 发布:php视频采集 编辑:程序博客网 时间:2024/06/06 09:33
题意
如果一个数可以表示为给定的两个数的非负整数幂之和,那么它就是不幸的,给定两个数a,b,求l到r区间内最多有多少个连续数字是非不幸的
思路
将a和b不超过r的非负整数幂先算出来,然后枚举相加,去重,将[l,r]之间的和放进vector,判断相邻两数之差,取最大,注意考虑首尾和vector为空的情况
代码
#include <cstdio>#include <set>#include <vector>#include <algorithm>using namespace std;vector<long long> xx,yy;set<long long> s;vector<long long> ss;int main(){ long long x,y,l,r,t,cnt,rr,ans; scanf("%I64d%I64d%I64d%I64d",&x,&y,&l,&r); t=1; cnt=0; rr=r; while(rr>0) { rr/=x; cnt++; } for(long long i=0;i<cnt;i++) { xx.push_back(t); t*=x; } t=1; cnt=0; rr=r; while(rr>0) { rr/=y; cnt++; } for(long long i=0;i<cnt;i++) { yy.push_back(t); t*=y; } for(long long i=0;i<xx.size();i++) for(long long j=0;j<yy.size();j++) { if(s.find(xx[i]+yy[j])==s.end()&&xx[i]+yy[j]>=l&&xx[i]+yy[j]<=r) { s.insert(xx[i]+yy[j]); ss.push_back(xx[i]+yy[j]); } } sort(ss.begin(),ss.end()); ans=0; for(long long i=0;i<ss.size();i++) { if(i==0) ans=max(ans,ss[i]-l); else ans=max(ans,ss[i]-ss[i-1]-1); if(i==ss.size()-1) ans=max(ans,r-ss[i]); } if(ss.empty()) ans=max(ans,r-l+1); printf("%I64d\n",ans); return 0;}
阅读全文
0 0
- Codeforces 813B The Golden Age 题解
- CodeForces 813B The Golden Age
- Codeforces 813 B 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(数学)
- Codeforces 875B Sorting the Coins 题解
- 《Golden Age》 --- 黄金时代
- Codeforces #835B: The Number on the Board 题解
- spark 集群安装
- 解决通达OA中Redis缓存服务和MQ队列服务起不来的问题
- @Controller和@RestController的区别?
- mybatis-全局配置文件-mybatis-config.xml-databaseIdProvider-9
- java中字节流与字符流的区别
- Codeforces 813B The Golden Age 题解
- AngularJs基础
- Xcode 8 真机调试 iOS 11 beta
- Java实现集合的组合(从组合中取出K个元素进行组合的所有情况)
- python3的文件与目录操作
- ToolBar完美教程
- phantomjs生成pdf
- 爱说话的小呆鸡 Chat Chat Dorky Chick 发布
- JavaScript制作微博发布栏效果