题意:给出一个大数数列,问是不是等比数列。

解法:拿java大数搞,注意全是0的情况也是Yes。我把公比用分数表示了,灰常麻烦,题解说只要判a[i - 1] * a[i + 1] == a[i] * a[i]就可以了,涨姿势了。

代码:

import java.math.*;
import java.util.Scanner; public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
while(cin.hasNext())
{
int T = cin.nextInt();
while(T-- != 0)
{
boolean flag = false;
BigInteger fenzi = BigInteger.ZERO;
BigInteger fenmu = BigInteger.ZERO;
boolean ans = true;
BigInteger a0 = BigInteger.ZERO, a1 = BigInteger.ZERO;
int n = cin.nextInt();
for(int i = 0; i < n; i++)
{
BigInteger x = cin.nextBigInteger();
if(!ans) continue;
if(i == 0)
{
if(x.equals(BigInteger.ZERO))
{
flag = true;
}
a0 = x;
}
else
{
if(flag)
{
if(!x.equals(BigInteger.ZERO))
ans = false;
}
else
{
if(x.equals(BigInteger.ZERO))
{
ans = false;
continue;
}
a1 = x;
if(i == 1)
{
BigInteger r = a0.gcd(a1);
fenzi = a1.divide(r);
fenmu = a0.divide(r);
}
else
{
BigInteger r = a0.gcd(a1);
if(!fenzi.equals(a1.divide(r)))
ans = false;
if(!fenmu.equals(a0.divide(r)))
ans = false;
}
a0 = a1;
}
}
}
if(ans)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
}

  

HDU 5429 Geometric Progression的更多相关文章

  1. hdu 5429 Geometric Progression(存个大数模板)

    Problem Description Determine whether a sequence is a Geometric progression or not. In mathematics, ...

  2. hdu 5429 Geometric Progression 高精度浮点数(java版本)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5429 题意:给一段长度不超过100的每个数字(可以是浮点数)的长度不超过1000的序列,问这个序列是否 ...

  3. hdu 5278 Geometric Progression 高精度

    Geometric Progression Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contes ...

  4. Codeforces Round #Pi (Div. 2) C. Geometric Progression map

    C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  5. CodeForces 567C Geometric Progression

    Geometric Progression Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  6. Codeforces Round #Pi (Div. 2) C. Geometric Progression

    C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input stan ...

  7. CodeForces 567C. Geometric Progression(map 数学啊)

    题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...

  8. map Codeforces Round #Pi (Div. 2) C. Geometric Progression

    题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...

  9. Codeforces 567C:Geometric Progression(DP)

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

随机推荐

  1. java基础知识回顾之javaIO类--File类应用:获取指定目录下面的指定扩展名的文件,将文件的绝对路径写入到目的文件当中

    /** * File文件综合应用 * 需求:获取指定目录下面,指定扩展名的文件,将文件的绝对路径写到文本文件当中. *  * 思路:1.需要深度遍历.--递归 * 2.遍历的过程中过滤指定扩展名的文件 ...

  2. java基础知识回顾之---java StringBuffer,Stringbuilder与String的区别

    public class StringBuilderTest { /** * StringBuffer和Stringbuilder :使用与内容可以被修改的字符串 * 与String的区别:Strin ...

  3. Android面试题基础(转)

    71道经典Android面试题和答案 1.下列哪些语句关于内存回收的说明是正确的? (b ) A. 程序员必须创建一个线程来释放内存 B.内存回收程序负责释放无用内存 C.内存回收程序允许程序员直接释 ...

  4. Java学习笔记之:Java String类

    一.引言 字符串广泛应用在Java编程中,在Java中字符串属于对象,Java提供了String类来创建和操作字符串. 创建字符串最简单的方式如下: String str= "Hello w ...

  5. python 编码问题(二)

    >>> a = '中文' >>> chardet.detect(a) {'confidence': 0.7525, 'encoding': 'utf-8'} > ...

  6. 修改linux命令行提示符路径显示

    命令显示行太长,影响观感,这样需要修改,具体方法: 1. 修改 ~/.bashrc,在最后一行添加: export PS1='[\u@\h\W]$' 其中\u是当前用户名,\h是当前主机名,\w显示当 ...

  7. 语言基础:C#运算符

    运算符 分类 符号 解释 优先级 算术运算符 ++   -- 加加  减减 由高到低,即执行顺序由上到下.(圆括号的优先级最高) *   /    % 乘  除  取余 +   - 加   减 关系运 ...

  8. Main()方法

    C#是从方法Main()开始执行的.这个方法必须是类或结构的静态方法,并且其返回类型必须是int或void .虽然显式指定p山屺修饰符是很常见的,因为按照定义,必须在程序外部调用该方法,但我们给该入口 ...

  9. 在Ubuntu上为Android系统内置Java应用程序测试Application Frameworks层的硬件服务(老罗学习笔记6)

    一:Eclipse下 1.创建工程: ---- 2.创建后目录 3.添加java函数 4.在src下创建package,在package下创建file 5.res---layout下创建xml文件,命 ...

  10. OEM - emctl resetTZ agent 设置时区

    [oracle@redhat4 config]$ cd $ORACLE_HOME/redhat4.7_orcl/sysman/config [oracle@redhat4 config]$ pwd/u ...