codeforces 789B. Masha and geometric depression

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

题意:给你b1,q,l,m。b1是等比数列第一项,q是公比,l是限制条件,如果某一项的绝对值大于l就结束等比,如果某一项等于ai就不计入数量。现在问你这个数列可以列到多少个

分析:就根据条件写即可,我看到题一开始考虑的就是q=0,q=1,q=-1,以及b1=0.这种情况才有可能出现无限多。其他情况模拟即可。

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 map<long long,int>mp;
 5 int main() {
 6     ios_base::sync_with_stdio(0);
 7     cin.tie(0);
 8     long long b,q,l,m;
 9     cin>>b>>q>>l>>m;
10     long long x;
11     for(int i=1;i<=m;i++){
12         cin>>x;
13         mp[x]=1;
14     }
15     if(q==0){
16         if(mp[0]!=1){
17             if(abs(b)<=l) cout<<"inf"<<endl;
18             else cout<<0<<endl;
19         }
20         else {
21             if(mp[b]!=1&&abs(b)<=l) cout<<1<<endl;
22             else cout<<0<<endl;
23         }
24     }
25     else if(q==1||q==-1){
26         if(mp[b]!=1){
27             if(abs(b)<=l) cout<<"inf"<<endl;
28             else cout<<0<<endl;
29         }
30         else if(mp[b*q]!=1){
31             if(abs(b*q)<=l) cout<<"inf"<<endl;
32             else cout<<0<<endl;
33         }
34         else cout<<0<<endl;
35     }
36     else {
37         int result=0;
38         if(b==0) {
39             if(mp[b]!=1){
40                 cout<<"inf"<<endl;
41             }
42             else cout<<0<<endl;
43         }
44         else {
45             while(abs(b)<=l){
46                 if(mp[b]!=1){
47                 result++;
48                 }
49                 b=b*q;
50             }
51             cout<<result<<endl;
52         }
53 
54     }
55 
56 return 0;
57 }
View Code

 

转载于:https://www.cnblogs.com/ls961006/p/6935450.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值