CF Infinite Sequence

2023-12-13 20:32
文章标签 cf sequence infinite

本文主要是介绍CF Infinite Sequence,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Infinite Sequence

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

描述

Vasyalikes everything infinite.  Now he isstudying the properties of a sequence s, such that its first element is equalto a (s1 = a), and the difference between any two neighbouring elements isequal to c (si - si - 1 = c).  Inparticular, Vasya wonders if his favourite integer b appears in this sequence,that is, there exists a positive integer i, such that si = b.  Of course, you are the person he asks for ahelp.

Vasya喜欢一切无限。现在,他正在研究一个序列s的属性,这样它的第一个元素等于a ,并且和任何两个相邻元素之间的区别=c(si - si - 1 = c)。特别是Vasya感兴趣他最喜欢整数b出现在这个序列,也就是说,存在一个正整数,这样如果=b。当然,你是他要求帮助的人。

 

 

Input

输入

Thefirst line of the input contain three integers a, b and c ( - 109  a, b, c  109)the first element of the sequence, Vasya's favorite number and the differencebetween any two neighbouring elements of the sequence, respectively.

输入的第一行包含三个整数a,bc(-109≤a,b,c≤109)-第一个元素的序列,Vasya最喜欢的数量和序列的任何两个相邻元素之间的区别,分别。

 

 

Output

输出

Ifb appears in the sequence s print "YES" (without quotes), otherwiseprint "NO" (without quotes).

如果b出现在序列s打印“YES”(没有引号),否则打印”(没有引号)

Sample Input

Input

17 3

Output

YES

Input

1010 0

Output

YES

Input

1-4 5

Output

NO

Input

060 50

Output

NO

 

题意:就是给定三个数a,b,c。判断能不能满足a+n*c==b

 

思路:1,考虑特殊情况

2,利用(b-a)/a的整型与浮点型答案比较,相等就是YES。另外 n >=0



/*=============================AC情况===============================*/
/*题目网址:   */
/*时间: */
/*心得:  */#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define G 100int main() {int sign1;double sign2,a,b,c;while(scanf("%lf%lf%lf",&a,&b,&c)!=EOF) {if(c==0) {if(a==b)printf("YES\n");elseprintf("NO\n");} else {sign1=(int)((b-a)/c);sign2=((b-a)/c);//printf("%d %lf",sign1,sign2);if(sign1>=0&&sign1==sign2)printf("YES\n");elseprintf("NO\n");}}return 0;
}/*********************************测试数据***********************************************************************************************************/



这篇关于CF Infinite Sequence的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/489867

相关文章

cf 164 C 费用流

给你n个任务,k个机器,n个任务的起始时间,持续时间,完成任务的获利 每个机器可以完成任何一项任务,但是同一时刻只能完成一项任务,一旦某台机器在完成某项任务时,直到任务结束,这台机器都不能去做其他任务 最后问你当获利最大时,应该安排那些机器工作,即输出方案 具体建图方法: 新建源汇S T‘ 对任务按照起始时间s按升序排序 拆点: u 向 u'连一条边 容量为 1 费用为 -c,

CF 508C

点击打开链接 import java.util.Arrays;import java.util.Scanner;public class Main {public static void main(String [] args){new Solve().run() ;} }class Solve{int bit[] = new int[608] ;int l

浙大数据结构:02-线性结构4 Pop Sequence

这道题我们采用数组来模拟堆栈和队列。 简单说一下大致思路,我们用栈来存1234.....,队列来存输入的一组数据,栈与队列进行匹配,相同就pop 机翻 1、条件准备 stk是栈,que是队列。 tt指向的是栈中下标,front指向队头,rear指向队尾。 初始化栈顶为0,队头为0,队尾为-1 #include<iostream>using namespace std;#defi

【UVA】1626-Brackets sequence(动态规划)

一道算是比较难理解的动规。 状态转移分2个: (用d[i][j]表示在i~j内最少需要添加几个括号,保持平衡) 1.如果s[i]和s[j]是一对括号,那么d[i][j] = d[i + 1][j - 1] 2.否则的话 d[i][j] = min(d[i][k],[k + 1][j]); 边界是d[i + 1][i] = 0; d[i][i] = 1; 13993644 162

【UVA】10534 - Wavio Sequence(LIS最长上升子序列)

这题一看10000的数据量就知道必须用nlog(n)的时间复杂度。 所以特意去看了最长上升子序列的nlog(n)的算法。 如果有2个位置,该位置上的元素为A[i]和A[j],并且他们满足以下条件: 1.dp[i] = dp[j]    (dp[x]代表以x结尾的最长上升子序列长度) 2.A[i] < A[j] 3.i < j 那么毫无疑问,选择dp[i] 一定优于选择dp[j] 那么

【CF】C. Glass Carving(二分 + 树状数组 + 优先队列 + 数组计数)

这题简直蛋疼死。。。。。 A了一下午 #include<cstdio>#include<queue>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const int maxn = 200005;int h,w,n;int C1[maxn],C2[maxn];int

【CF】E. Anya and Cubes(双向DFS)

根据题意的话每次递归分3种情况 一共最多25个数,时间复杂度为3^25,太大了 我们可以分2次求解第一次求一半的结果,也就是25/2 = 12,记录结果 之后利用剩余的一半求结果 s-结果 = 之前记录过的结果 就可以 时间复杂度降低为 3 ^ (n/2+1) 题目链接:http://codeforces.com/contest/525/problem/E #include<set

【CF】D. Arthur and Walls(BFS + 贪心)

D题 解题思路就是每次检查2X2的方格里是否只有一个‘*’,如果有的话这个*就需要变成‘.’,利用BFS进行遍历,入队的要求是这个点为. 一开始将所有的'.'全部加入队列,如果碰到一个'*'变成'.'就入队,判断的时候从4个方向就行判断 题目链接:http://codeforces.com/contest/525/problem/D #include<cstdio>#include<

CF#271 (Div. 2) D.(dp)

D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/474/problem/D We s

CF Bayan 2015 Contest Warm Up B.(dfs+暴力)

B. Strongly Connected City time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/475/probl