The number of spectators at the FIFA World Cup increases year after year. As you sell the advertisement slots during the games for the coming years, you need to come up with the price a company has to pay in order to get an advertisement slot. For this, you need a good estimate for the number of spectators in the coming games, based on the number of spectators in the past games.
Your intuition tells you that maybe the number of spectators could be modeled precisely by a polynomial of degree at most 3. The task is to check if this intuition is true.
Input
The input starts with a positive integer N, the number of test cases. Each test case consists of one line. The line starts with an integer 1 ≤ n ≤ 500, followed by n integers x1, ..., xn with 0 ≤ xi ≤ 50000000 for all i, the number of spectators in past games.
Output
For each test case, print YES if there is a polynomial p (with real coefficients) of degree at most 3 such that p(i) = xi for all i. Otherwise, print NO.
Example
Input: 3 1 3 5 0 1 2 3 4 5 0 1 2 4 5 Output: YES YES NO
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ff(a,n) for(int i = 0 ; i < n; i++) scanf("%d",a+i)
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
typedef pair<int,int> pii;
//inline ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&(-x);return res;}
//inline void add(int x,int d){while(x<=n)c[x]+=d,x+=x&(-x);}
//int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b);}
const ll inf = 0x3f3f3f3f;
const int mx = 505;
#define a (x[4]-3*x[3]+3*x[2]-x[1])/6
#define b (-2*x[4]+7*x[3]-8*x[2]+3*x[1])/2
#define c (42*x[2]-42*x[1]-42*7*a-42*3*b)
//#define d (x[1]-(a+b+c))
ll x[mx];
int main(){
// freopen("F:\\in.txt","r",stdin);
int T=10; scanf("%d",&T);
int n;
// ll a, b, c, d;
while(T--){
s1(n);
for(int i = 1; i <= n ;i++){
scanf("%lld",x+i);
}
if(n <= 4){
puts("YES");
}
else{
/*a = (x[4]-3*x[3]+3*x[2]-x[1])/6;
b = (x[3]-2*x[2]+x[1]-12*a)/2;
c = (x[2]-x[1]-7*a-3*b);
d = x[1]-(a+b+c);*/
// cout << a << "_ " << b <<"_" <<c <<"_" <<d <<endl;
int flag = 1;
flag = 1;
for (ll i = 5; i <= n; i++){
if (( 42*a * i * i * i + 42*b* i * i + c*i +42*x[1]- 42*a-42*b-c) !=42*x[i]){
flag = 0;
break;
}
}
if (flag)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
本文探讨了如何基于历史观众人数预测未来世界杯观众数量的方法,进而为广告位定价提供依据。通过对过去比赛观众人数的分析,利用多项式模型来判断是否可以精确地预测未来的观众规模。
1181

被折叠的 条评论
为什么被折叠?



