南邮 OJ 1389 Mountains of Pandora

Mountains of Pandora

时间限制(普通/Java) :  1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 56            测试通过 : 40 

比赛描述

The floating mountains of Pandora present a challenge for the human scientists, especially geologists

and physicists, who have been trying to understand how such structures could exist. While exploring

the mountains, the scientists stumbled across interesting stacked floating mountain structures, where

different mountains appeared stacked above one other, with the larger mountains being higher up in

the stack. The scientists were able to calculate the size of each mountain, and they made an interesting

observation: that the sizes of the mountains formed a (generalized) Fibbonacci sequence.

A sequence of numbers: x1, x2, ..., xn, is called a generalized Fibbonacci sequence if, for all i > 2,

xi = xi−1 + xi−2

The standard Fibbonacci sequence is simply a generalized Fibbonacci sequence with x1 = x2 = 1.

An example of generalized Fibbonacci sequence is: 2, 5, 7, 12, 19, ...

Your goal is to help the scientists verify this conjecture. Specifically, you are to write a program

that, given a sequence of numbers, decides whether the sequence is a generalized Fibbonacci sequence

or not.




输入

The first line in the test data file contains the number of test cases, n. After that, each line

contains one test case. The test case begins with the number of elements in the sequence, k, and then

we have k numbers which form the sequence. Assume all numbers are  0, and that the numbers are

all < 230.


输出

For each test case, you are to output “YES” (if the sequence is a generalized Fibbonacci

sequence) or “NO” (if it is not).


样例输入

3
6 1 1 2 3 5 8
7 1 2 2 4 6 10 16
4 2 10 12 22

样例输出

YES
NO
YES

提示

undefined

题目来源

Internet





#include<iostream>
#define MAX_N 1001

int a[MAX_N];

int main(){
	int cas,n,i;
	scanf("%d",&cas);
	while(cas--){
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",a+i);
		}
		for(i=2;i<n;i++){
			if(a[i]!=a[i-1]+a[i-2]){
				break;
			}
		}
		if(i<n){
			printf("NO\n");
		}else{
			printf("YES\n");
		}
	}
}





你可能感兴趣的:(ACM,of,pandora,南邮OJ,Mountains)