Avito Cool Challenge 2018 E. Missing Numbers 数学

E. Missing Numbers

在这里插入图片描述

solution

已知 a 1 , a 2 , a 3 , a 4 , . . . , a n − 1 , a n , 前 缀 和 s u m 2 [ i ] 均 为 平 方 数 , a_1,a_2,a_3,a_4,...,a_{n-1},a_n,前缀和sum^2[i]均为平方数, a1,a2,a3,a4,...,an1,an,sum2[i]

{ s u m [ 2 k + 1 ] = s u m 2 [ 2 k ] + x s u m [ 2 k + 2 ] = s u m 2 [ 2 k + 1 ] + y \begin{cases}sum[2k+1]=\sqrt{sum^2[2k] + x} \\sum[2k+2]=\sqrt{sum^2[2k+1] + y} \end{cases} { sum[2k+1]=sum2[2k]+x sum[2k+2]=sum2[2k+1]+y

= > => =>

{ s u m [ 2 k + 2 ] = s u m 2 [ 2 k + 1 ] + x + y s u m 2 [ 2 k + 2 ] ≥ ( s u m [ 2 k + 1 ] + 1 ) 2 y ≥ 2 ∗ s u m [ 2 k + 1 ] + 1 \begin{cases} sum[2k+2]=\sqrt{sum^2[2k+1] +x+ y} \\sum^2[2k+2]≥(sum[2k+1]+1)^2 \\y≥2*sum[2k+1]+1 \end{cases} sum[2k+2]=sum2[2k+1]+x+y sum2[2k+2](sum[2k+1]+1)2y2sum[2k+1]+1

= > => =>

a [ 2 k + 2 ] ≥ 2 ∗ s u m [ 2 k + 1 ] + 1 a[2k+2]≥2*sum[2k+1]+1 a[2k+2]2sum[2k+1]+1

code

/*Siberian Squirrel*/
/*Cute JinFish*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const double PI = acos(-1), eps = 1e-8;
/*const int MOD = 998244353, r = 119, k = 23, g = 3;
const int MOD = 1004535809, r = 479, k = 21, g = 3;*/
const int MOD = 1e9 + 7, INF = 0x3f3f3f3f;
const int N = 2e6 + 10, M = 1e7 + 10;

int sgn(double x) {
    
    
    if(fabs(x) < eps) return 0;
    return x < 0? -1: 1;
}
//inline int rnd(){static int seed=2333;return seed=(((seed*666666ll+20050818)%998244353)^1000000007)%1004535809;}
//double Rand() {return (double)rand() / RAND_MAX;}

int n;
ll a[N];

void init() {
    
    }

void solve(ll res = 0, ll st = 0, bool f = true) {
    
    
    for(int i = 1; i <= n; i += 2) {
    
    
        for(ll j = st + 1; ; ++ j) {
    
    
            ll x = j * j - st * st, y = a[i + 1];
            ll now = sqrt(j * j + a[i + 1]);
            if(now * now == j * j + a[i + 1]) {
    
    
                a[i] = x;
                st = now;
                break;
            }
            if(y < 2 * now + 1) {
    
    
                f = false;
                break;
            }
        }
    }
    if(!f) cout << "No" << endl;
    else {
    
    
        cout << "Yes" << endl;
        for(int i = 1; i <= n; ++ i) {
    
    
            if(i == 1) cout << a[i];
            else cout << ' ' << a[i];
        }
        cout << endl;
    }
}


int main() {
    
    
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(nullptr);
// srand(time(0));
#ifdef ACM_LOCAL
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    init();
    int o = 1;
//	cin >> o;
    while(o --) {
    
    
        cin >> n;
        for(int i = 1; i <= n / 2; ++ i) cin >> a[i << 1];
        solve();
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_46173805/article/details/115094764
今日推荐