B. The Golden Age
来源:互联网 发布:矩阵卷积计算方法 编辑:程序博客网 时间:2024/06/03 06:54
题目链接:http://codeforces.com/contest/813/problem/B
题意:就是有一个数叫做不幸运数,满足题目的 n = xa + yb,现在给你一个区间[l,r],让你找一个在这个区间里面一个最长的区间使得这个区间里面的所有数都不是不幸运数,让你输出最长区间的区间长度 ;
#include<cstdio>#include<algorithm>#define max_n 1010#include<cstring> #include<cmath>using namespace std;typedef long long LL;LL a[max_n],b[max_n],s[max_n];int main(){LL x,y,l,r;scanf("%lld %lld %lld %lld",&x,&y,&l,&r);a[0]=b[0]=1; int cnt1=1,cnt2=1; while(r/x>=a[cnt1-1]) //避免溢出 { a[cnt1]=a[cnt1-1]*x; cnt1++; } while(r/y>=b[cnt2-1]) { b[cnt2]=b[cnt2-1]*y; cnt2++; } int p=0; for(int i=0;i<cnt1;i++) for(int j=0;j<cnt2;j++) if(a[i]+b[j]>=l && a[i]+b[j]<=r) s[p++]=a[i]+b[j];sort(s,s+p);LL ans=0;if(p>0) //特判端点位置 ans=max(s[0]-l,r-s[p-1]); else ans=r-l+1;for(int i=0;i<p;i++) //滚动相减 {ans=max(s[i]-l-1,ans);l=s[i];}printf("%lld\n",ans);return 0;}
阅读全文
1 0
- B. The Golden Age
- B.The Golden Age
- CodeForces 813B The Golden Age
- Codeforces 813 B The Golden Age
- B. The Golden Age——math
- Codeforces 813B The Golden Age 题解
- codeforces round 22-B.the golden age
- CodeForces 813B The Golden Age
- The Golden Age CodeForces
- Educational Codeforces Round 22 B. The Golden Age(枚举)
- codeforces round 22 B.The Golden Age(枚举)
- The golden age of the developer
- The golden age of the developer
- Educational Codeforces Round 22-B. The Golden Age-暴力枚举+map
- CF813B:The Golden Age(数学)
- 《Golden Age》 --- 黄金时代
- The golden award
- China Is Poised for an I.T. Golden Age
- 图像数据转换成db(leveldb/lmdb)文件
- SDWebImage下载图片有时候无法成功显示出来
- [数据结构]Map和Set
- Effective c++ 学习笔记 (一)
- 排序之四:冒泡排序(C语言实现)
- B. The Golden Age
- ModelSim仿真实例教程
- pyhton -pickle使用方法(待补充)
- Redis的列表类型如何使用?
- 12c rac 操作系统内存低导致服务offline(opatch)
- 转C++内存管理
- openfire获取所有在线登录人
- textarea、input样式兼容
- Redis中的散列类型如何使用?