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

解法:拿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. POJ 1928

    #include <iostream> #include <algorithm> #define MAXN 3000 using namespace std; struct n ...

  2. struts2学习笔记(4)——数据类型转换

    回过头来看昨天的那个例子. 在昨天的例子中,只转换了一个Point类,如果想转换多个Point类怎么办呢?在昨天的例子上面做一个小的修改. 首先在input.jsp页面中修改几个输入框. <s: ...

  3. ubuntu安装google 输入法

    12.04 LTS Precise sudo apt-get install ibus ibus-clutter ibus-gtk ibus-gtk3 ibus-qt4 sudo apt-get in ...

  4. 欧拉工程第72题:Counting fractions

    题目链接:https://projecteuler.net/problem=72 真分数;n/d 当d ≤ 1,000,000时候的真分数有多少个 public class P72{ void run ...

  5. C内存分配函数

    C语言跟内存分配方式(1) 从静态存储区域分配.内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在.例如全局变量,static变量.(2) 在栈上创建.在执行函数时,函数内局部变量的 ...

  6. OpenCV源码阅读(2)---matx.h---函数的内联实现

    外部矩阵计算函数 namespace internal { template<typename _Tp, int m> struct Matx_DetOp { double operato ...

  7. WCF 简单示例

    WCF(Windows Communication Foundation,WCF)是基于Windows平台下开发和部署服务的软件开发包(Software Development Kit,SDK).WC ...

  8. Java API —— DateFormat类

    1.DateFormat类概述         DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间. 是抽象类,所以使用其子类SimpleDateForm ...

  9. linux下的共享库(动态库)和静态库

    1.什么是库在windows平台和linux平台下都大量存在着库.本质上来说库是一种可执行代码的二进制形式,可以被操作系统载入内存执行.由于windows和linux的本质不同,因此二者库的二进制是不 ...

  10. 面试题_1_to_16_多线程、并发及线程的基础问题

    多线程.并发及线程的基础问题 1)Java 中能创建 volatile 数组吗?能,Java 中可以创建 volatile 类型数组,不过只是一个指向数组的引用,而不是整个数组.我的意思是,如果改变引 ...