[Java 대수]hdu 5429 Geometric Progression
http://acm.hdu.edu.cn/showproblem.php?pid=5429
Problem Description Determine whether a sequence is a Geometric progression or not. In mathematics, a geometric progression, also known as a geometric sequence, is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, … is a geometric progression with common ratio 3. Similarly 10, 5, 2.5, 1.25, … is a geometric sequence with common ratio 1/2. Examples of a geometric sequence are powers rk of a fixed number r, such as 2k and 3k. The general form of a geometric sequence is a, ar, ar2, ar3, ar4, … where r ≠ 0 is the common ratio and a is a scale factor, equal to the sequence’s start value. Input First line contains a single integer T(T≤20) which denotes the number of test cases. For each test case, there is an positive integer n(1≤n≤100) which denotes the length of sequence,and next line has n nonnegative numbers Ai which allow leading zero.The digit’s length of Ai no larger than 100. Output For each case, output “Yes” or “No”.
제목
n 개 수 를 주어 등비 수열 을 구성 할 수 있 는 지 판단 한다(주의 수의 범위)
예시
Sample Input 4 1 0 3 1 1 1 3 1 4 2 5 16 8 4 2 1 Sample Output Yes Yes No Yes
사고의 방향
빅 데이터,내 가 쓰 는 JAVA!
참조 코드
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{
static BigInteger []a = new BigInteger [110];
static BigInteger zero = BigInteger.ZERO;
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
int T = cin.nextInt();
while(T-- >0){
int n = cin.nextInt();
boolean has0 = false,all0 = true;
for(int i = 0; i < n; ++ i){
a[i] = cin.nextBigInteger();
if(a[i].compareTo(zero) == 0) has0 = true;
else all0 = false;
}
if(all0 == true){System.out.println("Yes");continue;}
if(has0 == true){System.out.println("No");continue;}
boolean ok = true;
for(int i = 2; i < n; ++ i){
if(a[i-1].multiply(a[i-1]).equals(a[i-2].multiply(a[i])) == false)
{
ok = false;
break;
}
}
if(ok) System.out.println("Yes");
else System.out.println("No");
}
}
}
Ctrl + B
Ctrl + I
Ctrl + Q
Ctrl + L
Ctrl + K
Ctrl + G
Ctrl + H
Ctrl + O
Ctrl + U
Ctrl + R
Ctrl + Z
Ctrl + Y
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
hdu5569 BestCoder Round #63 (div.2)제목: 행렬을 하나 드릴게요. 왼쪽 상단에서 오른쪽 하단까지 가는 비용을 요구합니다. a[1]*a[2]+a[3]*a[4]+......+a[2n-1]*a[2n] 아이디어: 과연 슬기롭지 못하여, 스스로 방법을 강구했다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.