614A - Link/Cut Tree 数乘
2 seconds
256 megabytes
standard input
standard output
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Given integers l, r and k, you need to print all powers of number k within range from l to rinclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
The first line of the input contains three space-separated integers l, r and k (1 ≤ l ≤ r ≤ 1018,2 ≤ k ≤ 109).
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
1 10 2
1 2 4 8
2 4 5
-1
Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed.
题意:给你一个区间[l,r]和一个数k,求k^0,k^1,k^2这些数字中处于该区间的数,并输出这些数
错因分析:看到题目第一反应就是想到了快速幂,然后迅速的写了上去,结果后来才意识到
快速幂会犯一个比较麻烦的的错误;直接将数相乘就好了嘛,干嘛要那么麻烦的快速幂,定势思维了
下面第一个是AC代码
#include<cstdio>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include<map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
int main()
{
long long l,r,v;
while(~scanf("%lld %lld %lld",&l,&r,&v))
{
int flag=0;long long ans=1;
while(ans<=r)
{
if(ans>=l)
{
flag=1;
printf("%lld ",ans);
}
if(r/v>=ans)/*写成乘的形式是可能会爆long long的
因此是错误的额*/
ans*=v;
else
break;
}
if(!flag)
printf("-1");
printf("\n");
}
return 0;
}
下面是wa的代码注意WA原因是不太好避免上面指出的那个错误:
#include<cstdio>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include<map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
long long cimi(long long a,long long p)
{
long long res=1,temp=a;
while(p)
{
if(p&1)
res*=temp;
temp*=temp;
p>>=1;
}
return res;
}
int main()
{
long long l,r,v;
while(~scanf("%lld %lld %lld",&l,&r,&v))
{
int flag=0;long long ans=0;
for(long long i=0;;i++)
{
ans=cimi(v,i);
if(ans>=l&&ans<=r)
{
printf("%lld ",ans);
flag=1;
}
else if(ans>r)
break;
}
if(!flag)
printf("-1");
printf("\n");
}
return 0;
}
614A - Link/Cut Tree 数乘的更多相关文章
- CodeForces 614A Link/Cut Tree
#include<cstdio> #include<cstring> #include<cmath> #include<stack> #include& ...
- [CodeForces - 614A] A - Link/Cut Tree
A - Link/Cut Tree Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, ...
- Link Cut Tree学习笔记
从这里开始 动态树问题和Link Cut Tree 一些定义 access操作 换根操作 link和cut操作 时间复杂度证明 Link Cut Tree维护链上信息 Link Cut Tree维护子 ...
- link cut tree 入门
鉴于最近写bzoj还有51nod都出现写不动的现象,决定学习一波厉害的算法/数据结构. link cut tree:研究popoqqq那个神ppt. bzoj1036:维护access操作就可以了. ...
- Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题
A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...
- Link/cut Tree
Link/cut Tree 一棵link/cut tree是一种用以表示一个森林,一个有根树集合的数据结构.它提供以下操作: 向森林中加入一棵只有一个点的树. 将一个点及其子树从其所在的树上断开. 将 ...
- 洛谷P3690 Link Cut Tree (模板)
Link Cut Tree 刚开始写了个指针版..调了一天然后放弃了.. 最后还是学了黄学长的板子!! #include <bits/stdc++.h> #define INF 0x3f3 ...
- LCT总结——概念篇+洛谷P3690[模板]Link Cut Tree(动态树)(LCT,Splay)
为了优化体验(其实是强迫症),蒟蒻把总结拆成了两篇,方便不同学习阶段的Dalao们切换. LCT总结--应用篇戳这里 概念.性质简述 首先介绍一下链剖分的概念(感谢laofu的讲课) 链剖分,是指一类 ...
- bzoj2049 [Sdoi2008]Cave 洞穴勘测 link cut tree入门
link cut tree入门题 首先说明本人只会写自底向上的数组版(都说了不写指针.不写自顶向下QAQ……) 突然发现link cut tree不难写... 说一下各个函数作用: bool isro ...
随机推荐
- VNC 设置分辨率 --TigerVNC
之前写过如何设置vnc https://www.cnblogs.com/jinanxiaolaohu/p/9110002.html 如果想设置vnc的分辨率的话 也很简单 如图示: vncserver ...
- mysql拆分逗号一列变多行
需求: SELECT ), ) FROM TABLE a INNER JOIN mysql.help_topic b )
- [转帖]docker清理日志
docker清理日志 2017年05月03日 10:37:27 不想当码农的程序员 阅读数 12827 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn. ...
- JavaSE 基础
一.Java 面向对象 1. 面向对象都有哪些特性以及 你对这些特性的理解 1.1. 继承: 继承是从已有类得到继承信息创建新类的过程. 提供继承信息的类被称为父类(超类,基类);得到继承信息的类被称 ...
- NIKKEI Programming Contest 2019-2 Task E. Non-triangular Triplets
$\require{enclose}$ 必要条件 一方面 $\sum_{i=1}^{N}(a_i + b_i) \le \sum_{i=1}^{N} c_i \implies 2\sum_{i=1}^ ...
- mysql索引失效的情况
1.WHERE字句的查询条件里有不等于号(如:WHERE column!=...),MYSQL将无法使用索引: 2.WHERE字句的查询条件里使用了函数的列(如:WHERE DAY(column)=. ...
- Echarts饼图将数据显示在 legend 旁边
不多废话,笔记如下 var myEcharts = echarts.init(document.getElementById('doughnut')); option = { tooltip: { t ...
- Oracle DBA 学习总结
对于学习Oracle 数据库,应该先要了解Oracle 的框架.它有物理结构(由控制文件.数据文件.重做日志文件.参数文件.归档文件.密码文件组成) ,逻辑结构(表空间.段.区.块),内存分配( SG ...
- HTTP协议请求过程
HTTP协议请求过程分析 步骤:用户输入URL,以www.yxh.com为例,获得主机名后,进行DNS域名解析, 首先,浏览器自身会查找自己缓存,没有的话,寻找本机的hosts文件,本机hosts没有 ...
- Powershell - 获取服务器启动时间
www.orangeisland.cn 使用以下命令,直接获取服务器启动时间: 通过以下脚本,批量获取服务器的启动时间: $TextPath = "C:\Users\admin\Deskto ...