【codeforces 789B】Masha and geometric depression
【题目链接】:http://codeforces.com/contest/789/problem/B
【题意】
让你一个一个地写出等比数列的每一项
(注意是一个一个地写出);
有m个数字不能写;
且数字大于l的不写(大于l了就停止不再继续写)
【题解】
特判b1=0,q=0,q=1,q=-1的情况就好;
有个很坑的地方就是,如果b1>l了,那么b2..bn就不能再计算了,因为在b1处就已经停止了;->在q=0的时候要先判断b1是不是大于l,是大于l就不用再考虑后面的0了.
具体的看代码吧.
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110;
LL b1, q, l, m, ans = 0;
map <int, int> dic;
void in()
{
rel(b1), rel(q), rel(l), rel(m);
rep1(i, 1, m)
{
int x;
rei(x);
dic[x] = 1;
}
}
void out()
{
exit(0);
}
void special()
{
if (b1 == 0)
{
if (dic[0])
puts("0");
else
puts("inf");
out();
}
if (q == 0)//b1!=0
{
int ju1 = dic[b1], ju2 = dic[0];
if (abs(b1) > l)//如果第一个数字就是大于l的,后面的0不能算
{
puts("0");
out();
}
if (ju2 == 0)
{
puts("inf");
}
else//不能写0
{
if (abs(b1) <= l)//第一个数字在l范围内
{
if (ju1 == 0)
puts("1");
else
puts("0");
}
else//不在l范围内,第一个数字也不能写
{
puts("0");
}
}
out();
}
if (q == 1)
{
//b1已经确定不会为0了
if (abs(b1) <= l)
{
if (dic[b1])
{
puts("0");
}
else
puts("inf");
}
else//不在l范围内,直接不能输出
puts("0");
out();
}
if (q == -1)
{
//b1 和 -b1交替出现
//b1确定不会为0了
if (abs(b1) <= l)
{
if (dic[b1] && dic[-b1])
{
puts("0");
}
else
puts("inf");
}
else
puts("0");
out();
}
}
void get_ans()
{
LL temp = b1;
while (abs(temp) <= l)
{
if (!dic[temp])
{
ans++;
}
temp = temp*q;
}
}
void o()
{
cout << ans << endl;
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
in();//checked
special();//checked
get_ans();//checked
o();
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【codeforces 789B】Masha and geometric depression的更多相关文章
- 【cf789B】Masha and geometric depression(分类讨论/暴力)
B. Masha and geometric depression 题意 在黑板上写数列,首项是b,公比是q,超过l时就停止不写.给定m个数,遇到后跳过不写.问一共写多少个数,如果无穷个输出inf. ...
- CodeForces - 789B B. Masha and geometric depression---(水坑 分类讨论)
CodeForces - 789B 当时题意理解的有点偏差,一直wa在了14组.是q等于0的时候,b1的绝对值大于l的时候,当b1的绝对值大于l的时候就应该直接终端掉,不应该管后面的0的. 题意告诉你 ...
- CF789B. Masha and geometric depression
/* CF789B. Masha and geometric depression http://codeforces.com/contest/789/problem/B 水题 各种特判,贼烦 */ ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- codeforces 789 B. Masha and geometric
链接 B. Masha and geometric depression 题意 给你一个等比数列的首项和公比q,然后给出一个上限l,m个数字,在这个等比数列里,小于l且没有在m个数字里面出现过的可以写 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- iOS音频篇:使用AVPlayer播放网络音乐
http://www.cocoachina.com/ios/20160324/15767.html 引言 假如你现在打算做一个类似百度音乐.豆瓣电台的在线音乐类APP,你会怎样做? 首先了解一下音频播 ...
- 【水滴石穿】react-native忽略黄色提醒
方法一 import { YellowBox } from 'react-native'; YellowBox.ignoreWarnings(['Remote debugger']); // 忽略黄色 ...
- Dalvik 虚拟机和 Sun JVM 在架构和执行方面有什么本质区别?
目前我理解的是: 两者共同点: 都是解释执行 byte code 都是每个 OS 进程运行一个 VM,并执行一个单独的程序 在较新版本中(Froyo / Sun JDK 1.5)都实现了相当程度的 J ...
- JasperStudio 输出pdf 出错。
发表于 2008-09-23 09:35:15 楼主net.sf.jasperreports.engine.JRException: Error retrieving field value from ...
- 信息摘要算法 MessageDigestUtil
package com.xgh.message.digest.test; import java.math.BigInteger; import java.security.MessageDigest ...
- WPF程序国际化
1.创建相应的xaml文件 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presen ...
- JavaScript--轮播图_带计时器
轮播图效果: 实现的功能: 1.鼠标移入,左右按钮显示 2.右下叫小圆点鼠标移入,进入下一张图 3.左右按钮点击,右下小圆点页跟随变更 4.自动开启计时器,鼠标移入右下叫小圆点区,计时器停止,鼠标移出 ...
- Python学习之路7☞装饰器
一:命名空间与作用域 1.1命名空间 局部命名空间: def foo(): x=1 def func(): pass 全局命名空间: import time class ClassName:pass ...
- 云原生生态周报 Vol. 2
摘要: Cloud Native Weekly China Vol. 2 业界要闻 Kubernetes External Secrets 近日,世界上最大的域名托管公司 Godaddy公司,正式宣布 ...
- @atcoder - AGC035D@ Add and Remove
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 N 张排成一行的卡片,第 i 张卡片上面写着 Ai. 重复 ...