HDU 5429 Geometric Progression
题意:给出一个大数数列,问是不是等比数列。
解法:拿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的更多相关文章
- hdu 5429 Geometric Progression(存个大数模板)
Problem Description Determine whether a sequence is a Geometric progression or not. In mathematics, ...
- hdu 5429 Geometric Progression 高精度浮点数(java版本)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5429 题意:给一段长度不超过100的每个数字(可以是浮点数)的长度不超过1000的序列,问这个序列是否 ...
- hdu 5278 Geometric Progression 高精度
Geometric Progression Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contes ...
- 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 ...
- CodeForces 567C Geometric Progression
Geometric Progression Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- 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 ...
- CodeForces 567C. Geometric Progression(map 数学啊)
题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...
- map Codeforces Round #Pi (Div. 2) C. Geometric Progression
题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...
- Codeforces 567C:Geometric Progression(DP)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
随机推荐
- lintcode:最大子正方形
题目: Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square contain ...
- jsp片段
转载自:http://blog.csdn.net/lovejavaydj/article/details/7293145 使用jspf 在开发中写jsp页面时,通常都要通过如下方式在jsp文件头部引入 ...
- Windows下Subversion和Apache的安装及配置(一)
1.序 Subversion可谓版本控制软件中的佼佼者,其开源性,易用性已受到众多软件开发者首选的版本控制软件.在这里我想记录我安装Subversion和Apache的过程.注意,Subversion ...
- SQL Server查询优化方法(查询速度慢的原因很多,常见如下几种) .
今天看到一位博友的文章,觉得不错,转载一下,希望对大家有帮助,更多文章,请访问:http://blog.haoitsoft.com 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺 ...
- mysql中bigint在php中表示
http://bbs.csdn.net/topics/340266753 http://www.percona.com/blog/2008/01/10/php-vs-bigint-vs-float-c ...
- c语言 快排排序
快速排序(Quick Sort): 这个算法的霸气程度从它的名字就可以看出来了.快速排序的应用也是非常广的的,各种类库都可以看到他的身影.这当然与它的“快”是有联系的,正所谓天下武功唯快不破. 快速排 ...
- Android的NDK开发(4)————JNI数据结构之JNINativeMethod
转至:http://blog.csdn.net/conowen/article/details/7524744 1.JNINativeMethod 结构体的官方定义 typedef struct { ...
- ExtJs自学教程(1):一切从API开始
题 记 该系列文章不侧重全方位的去介绍ExtJs的使用,只是侧重于解决ExtJs问题的思考方法.写的人不用长篇大论,学的人则能够自立更生.l 学习的人只要有一些CSS的javascript的基础知识 ...
- mac更新node
今天在用 yeoman 的时候,提示对 npm 和 node 的版本有要求,为了决绝以后遇到的一些类似的问题,我决定定期对 node 和 npm 进行更新. npm的更新: $ sudo npm in ...
- 使用Quartz创建定时任务
项目开发中经常需要定时循环执行某些任务 比如定时发送报表,定时发送邮件,亦或者定时清理缓存,定时更新数据等等 有些时候可以简单地利用Windows Server的计划任务执行程序 Linux也有相应的 ...