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 : ...
随机推荐
- Java Notes
1.java是解释型语言.java虚拟机能实现一次编译多次运行. 2.JDK(java software Development kit 软件开发包),JRE(java Runtime Environ ...
- sqlserver 空间数据类型
--.建立有空间数据的表 create table x ( v ,) primary key, geog geography not null, geogWKT as geog.STAsText() ...
- MyBatis Mapper 文件例子
转载:http://blog.csdn.net/ppby2002/article/details/20611737 <?xml version="1.0" encoding= ...
- java nio2
Buffer的基本用法 使用Buffer读写数据一般遵循以下四个步骤: 写入数据到Buffer 调用flip()方法 从Buffer中读取数据 调用clear()方法或者compact()方法 当向b ...
- Windows下Subversion和Apache的安装及配置(一)
1.序 Subversion可谓版本控制软件中的佼佼者,其开源性,易用性已受到众多软件开发者首选的版本控制软件.在这里我想记录我安装Subversion和Apache的过程.注意,Subversion ...
- Linux磁盘管理命令
1.磁盘分割: fdisk [root@linux ~]# fdisk [-l] 装置名称 参数: -l :输出后面接的装置所有的partition内容.若仅有fdisk -l时, 则系统将会把整个系 ...
- WCF入门(八)---WCF服务绑定
WCF服务绑定是一个集合,每个元素定义了服务与客户端进行通信方式的几个元素.传输元素和一个消息编码元素各自结合两个最重要的组成部分.这里是WCF服务绑定常用的列表. 基础绑定 基础约束是由basicH ...
- 使用CXF暴露您的REST服务
使用CXF暴露您的REST服务 REST应用服务器SpringBeanServlet 1. 前言 现在互联网Open API流行,将您的Web应用也可以开放Open API给其他第三方使用.达到一 ...
- TCP和UDP协议的应用/参数查看
TCP发送的包有序号,对方收到包后要给一个反馈,如果超过一定时间还没收到反馈就自动执行超时重发,因此TCP最大的优点是可靠.一般网页(http).邮件(SMTP).远程连接(Telnet).文件(FT ...
- maven小试牛刀
Maven是一个采用纯Java编写的开源项目管理工具.Maven采用了一种被称之为project object model (POM)概念来管理项目,所有的项目配置信息都被定义在一个叫做POM.xml ...