• codeforces 675A A. Infinite Sequence(水题)


    题目链接:

    A. Infinite Sequence

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer bappears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.

    Input
     

    The first line of the input contain three integers ab and c ( - 10^9 ≤ a, b, c ≤ 10^9) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.

    Output
     

    If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).

    Examples
     
    input
    1 7 3
    output
    YES
    input
    10 10 0
    output
    YES
    input
    1 -4 5
    output
    NO
    input
    0 60 50
    output
    NO
    Note

    In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.

    In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.

    In the third sample all elements of the sequence are greater than Vasya's favorite integer.

    In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.

    题意:

    给数列的首项,再给出数列的相邻的差,给出一个数问是否出现在这个数列中;

    思路:

    简单的分情况讨论了;

    AC代码:

    #include <bits/stdc++.h>
    using namespace std;
    #define Riep(n) for(int i=1;i<=n;i++)
    #define Riop(n) for(int i=0;i<n;i++)
    #define Rjep(n) for(int j=1;j<=n;j++)
    #define Rjop(n) for(int j=0;j<n;j++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    typedef long long LL;
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=0x3f3f3f3f;
    const int N=1e4+25;
    int n;
    int main()
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        if(c==0){if(a==b)printf("YES
    ");
        else printf("NO
    ");}
        else if(c>0)
        {
        if((b-a)%c==0&&b>=a)printf("YES
    ");
        else printf("NO
    ");
        }
        else
        {
            c=-c;
            if((a-b)%c==0&&b<=a)printf("YES
    ");
            else printf("NO
    ");
        }
    
        return 0;
    }
  • 相关阅读:
    链式前向星存树图和遍历它的两种方法【dfs、bfs】
    JavaScript——WEBAPIS_自定义属性,以及节点操作
    JavaScript——WebAPIs-入门
    JavaScript——函数的深入和一些常见的内置对象
    JavaScript——数组&函数
    JavaScript——运算符&分支结构&循环结构
    Hover.css动画库,简单使用,和源码解析
    Animate.css动画库,简单的使用,以及源码剖析
    Linux发行版Ubuntu下的Python开发环境的配置
    Python简单介绍
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5502133.html
Copyright © 2020-2023  润新知