CodeForces 813B The Golden Age
来源:互联网 发布:mac 格式化u盘 编辑:程序博客网 时间:2024/06/06 06:54
题目链接:http://codeforces.com/contest/813/problem/B
题意:就是有一个数叫做不幸运数,他满足题目的那个公式,现在给你一个区间[l,r],让你找一个在这个区间里面一个最长的区间使得这个区间里面的所有数都不是不幸运数,让你输出最长区间的区间长度
解析:其实可以直接把这个区间里面的所有不幸运数全部都处理出来,然后维护一下最长的区间长度就可以了,不过对于[l,r]两个端点要特殊处理一下
#include <bits/stdc++.h>using namespace std;long long a[105],b[105];vector<long long> tt;int main(void){ long long x,y,l,r; scanf("%I64d %I64d %I64d %I64d",&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++; } 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) tt.push_back(a[i]+b[j]); } } sort(tt.begin(),tt.end()); long long ans = 0; if(tt.size()) ans = max(tt[0]-l,r-tt[tt.size()-1]); else ans = r-l+1; for(unsigned int i = 0;i<tt.size();i++) { ans = max(tt[i]-l-1,ans); l = tt[i]; } printf("%I64d\n",ans); 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
- intellij安装配置Tomcat
- Android布局优化技巧
- netperf 与网络性能测量
- Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/ServletContext
- js面向对象的理解
- CodeForces 813B The Golden Age
- java多线程学习-java.util.concurrent详解(一) Latch/Barrier
- win7 命令历史查看
- Android应用的多语言支持
- C# 判断手机访问的方法
- Java 垃圾回收器的GC机制,看这一篇就够了
- Windows下Mongodb安装及配置
- 全微分方程
- 移动端meta常规设置