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 : ...
随机推荐
- 空格的URL编码
Q: 为什么我看的教材一会说是“+” 一会说是“%20” A: urlencode(" ") '返回+encodeURI(" ") '返回%20是有区别的
- cojs 疯狂的求和问题 解题报告
QAQ 好久不在cojs上出题了 最近学了点新科技,于是就做成题来分享了 这道题是要求simga(i^k) 那么就先说说部分分的算法吧: 10分: 直接暴力就可以了,时间复杂度O(nlogk) 30分 ...
- java四种数组排序
数组的四种排序 1.快速排序法Arrays.sort(); 用法1.sort(byte[] a) 对指定的 byte 型数组按数字升序进行排序. sort(byte[] a, int fro ...
- C内存分配函数
C语言跟内存分配方式(1) 从静态存储区域分配.内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在.例如全局变量,static变量.(2) 在栈上创建.在执行函数时,函数内局部变量的 ...
- sql的内连接 左外连接 右外连接 全外连接等连接查询的关系图
经常会用到的,下面用图来表示各个连接
- 2014-9-17二班----9 web project
http://localhost:8080/rwkj1/indexServlet 跳转 http://localhost:8080/rwk ...
- Android:ViewPager制作幻灯片
布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:androi ...
- servlet会话技术:Session
问题的引出 1.在网上购物时,张三和李四购买的商品不一样,他们的购物车中显示的商品也不一样,这是怎么实现的呢? 2.不同的用户登录网站后,不管该用户浏览该网站的那个页面,都可以显示登录人的名字,同时可 ...
- linux快速修改文件夹及文件下所有文件与文件夹权限
分两部分改属主和权限: 更改权限,递归方式 chmod -R 755 /var/www/html/test.com 更改属主,递归 chown -R apache:apache /var/www/ht ...
- S5P4418iNand清空方法
01连接串口线 02打开Fastboot的Xshell串口插件 03启动开发板 04一启动就输入回车键 05在uboot处停住,输入:mmc erase blk 10000 (mmc erase bo ...