题目链接:http://codeforces.com/contest/813/problem/B

题意:就是有一个数叫做不幸运数,满足题目的 n = x^a + y^b,现在给你一个区间[l,r],让你找一个在这个区间里面一个最长的区间使得这个区间里面的所有数都不是不幸运数,让你输出最长区间的区间长度 。

先用两个数组将x的n次方和y的n次方存起来,然后暴力枚举,用map将符合的条件的数存起来,不幸运数的区间就是两个幸运数的位置之差相减再减1。(注意map迭代器的用法)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1)
const int INF = 0x3f3f3f3f;
const ll N=1e18;
map<ll,ll>ma;
ll x[],y[]; int main()
{
memset(x,,sizeof(x));
memset(y,,sizeof(y));
ll a,b,l,r;
scanf("%I64d%I64d%I64d%I64d",&a,&b,&l,&r);
x[]=;
y[]=;
ma[l-]=;
ma[r+]=;
for(int i=; x[i-]<=N/a; i++)
x[i]=x[i-]*a;
for(int i=; y[i-]<=N/b; i++)
y[i]=y[i-]*b;
for(int i=; x[i]!=; i++)
for(int j=; y[j]!=; j++)
if(x[i]+y[j]<=r&&x[i]+y[j]>=l)
ma[x[i]+y[j]]=;
map<ll,ll>::iterator fir,sec;
sec=ma.begin();
fir=ma.begin();
sec++;
ll ans=;
for(; sec!=ma.end(); fir++,sec++)
ans=max(ans,sec->first-fir->first-);
printf("%I64d",ans);
return ;
}

Educational Codeforces Round 22 B. The Golden Age(暴力)的更多相关文章

  1. Educational Codeforces Round 22 E. Army Creation

    Educational Codeforces Round 22 E. Army Creation 题意:求区间[L,R]内数字次数不超过k次的这些数字的数量的和 思路:和求区间内不同数字的数量类似,由 ...

  2. Educational Codeforces Round 22.B 暴力

    B. The Golden Age time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Educational Codeforces Round 22 补题 CF 813 A-F

    A The Contest 直接粗暴贪心 略过 #include<bits/stdc++.h> using namespace std; int main() {//freopen(&qu ...

  4. Educational Codeforces Round 22 E. Army Creation 主席树 或 分块

    http://codeforces.com/contest/813/problem/E 题目大意: 给出长度为n的数组和k,  大小是1e5级别. 要求在线询问区间[l, r]权值,  权值定义为对于 ...

  5. [Educational Codeforces Round#22]

    来自FallDream的博客,未经允许,请勿转载,谢谢. 晚上去clj博客逛来逛去很开心,突然同学提醒了一下,发现cf已经开始40分钟了,慌的一B,从B题开始写,写完了B到E最后收掉了A,结果太着急B ...

  6. 【Educational Codeforces Round 22】

    又打了一场EDU,感觉这场比23难多了啊…… 艹还是我太弱了. A. 随便贪心一下. #include<bits/stdc++.h> using namespace std; ,ans=- ...

  7. Educational Codeforces Round 22 E. Army Creation(分块好题)

    E. Army Creation time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. Codeforces Educational Codeforces Round 5 B. Dinner with Emma 暴力

    B. Dinner with Emma 题目连接: http://www.codeforces.com/contest/616/problem/A Description Jack decides t ...

  9. Educational Codeforces Round 11 D. Number of Parallelograms 暴力

    D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...

随机推荐

  1. bitmap位图原理和实现

    引子 首先通过一道题来理解什么是bitmap. 题目:我有40亿个整数,再给一个新的整数,我需要判断新的整数是否在40亿个整数中,你会怎么做? 分析: 假设一个int占4个字节(32位),40个亿个整 ...

  2. PTA(Basci Level)1043.输出PATest

    给定一个长度不超过 104 的.仅由英文字母构成的字符串.请将字符重新调整顺序,按 PATestPATest.... 这样的顺序输出,并忽略其它字符.当然,六种字符的个数不一定是一样多的,若某种字符已 ...

  3. Guava 工具类之joiner的使用

    joiner主要用于对字符串的连接,也可用于对map中key value的连接 public class JoinerTest { private static final List<Strin ...

  4. Linux 下面安装 nginx 以及进行TCP反向代理、负载均衡的过程

    1. 下载安装nginx 注意 因为stream 并不是 nginx自带的module  所以需要 在安装是 通过 --with 的方式增加上. 下载必要的程序包 # openssl wget htt ...

  5. 华为CPU的类型

    主要分类: 以及 一句名言

  6. 性能工具之JMeter+InfluxDB+Grafana打造压测可视化实时监控(centos7环境)

    前提条件,已经安装jmeter并可以运行 1.安装influxdata wget et https://dl.influxdata.com/influxdb/releases/influxdb-1.7 ...

  7. Linux系列之压缩与解压

    1.压缩技术 1.常用命令实例 1.zip格式的压缩与解压缩 zip是压缩指令,unzip是解压指令.zip指令既可以压缩文件,也可以压缩目录.压缩会自动保留源文件,解压会自动保留压缩文件. zip  ...

  8. resful规范: 进行数据交换时的代码潜规则

    目前主流的三种web服务交互方案: REST (Representational State Transfer) 表征性状态转移 SOAP (Simple Object Access Protocol ...

  9. AlertManager 部署及使用

    熟悉了 Grafana 的报警功能,但是 Grafana 的报警功能目前还比较弱,只支持 Graph 的图表的报警.今天来给大家介绍一个功能更加强大的报警工具:AlertManager. 简介 之前我 ...

  10. Mysql数据库的优化(本文摘自于网络,文章末端有原文链接)

    对于一个以数据为中心的应用,数据库的好坏直接影响到程序的性能,因此数据库性能至关重要.一 般来说,要保证数据库的效率,要做好以下四个方面的工作: ① 数据库设计 ② sql语句优化 ③ 数据库参数配置 ...