• 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
  • 相关阅读:
    php获取http请求原文
    windows下安装MongoDB服务
    微服务RESTful 接口设计规范
    mysql主从复制原理及步骤
    nodejs主要框架
    redis事务机制和分布式锁
    计算机专业学生一定要学好这几门课
    redis常见7种使用场景
    js类型判断
    SQL语句:case when then的用法
  • 原文地址:https://www.cnblogs.com/ls961006/p/6935450.html
Copyright © 2020-2023  润新知