zoukankan      html  css  js  c++  java
  • CF1081E Missing Numbers

    思路:

    贪心乱搞。

    实现:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 
     5 const ll m = 1e13;
     6 
     7 ll a[100005], b[100005];
     8 
     9 bool check(ll x)
    10 {
    11     ll s = sqrt(x);
    12     return s * s == x;
    13 }
    14 
    15 int main()
    16 {
    17     int n;
    18     while (cin >> n)
    19     {
    20         for (int i = 1; i <= n / 2; i++) cin >> a[i];
    21         ll p = 1;
    22         while (p * p <= m && !check(p * p + a[1])) p++;
    23         if (p * p > m) { cout << "No" << endl; continue; }
    24         b[1] = p * p;
    25         ll sum = b[1] + a[1];
    26         int i = 2;
    27         for ( ; i <= n / 2; i++)
    28         {
    29             while (p * p <= sum + m && (p * p <= sum || !check(p * p + a[i]))) p++;
    30             if (p * p > sum + m) break;
    31             b[i] = p * p - sum; sum = p * p + a[i];
    32         }
    33         if (i != n / 2 + 1) { cout << "No" << endl; continue; }
    34         cout << "Yes" << endl;
    35         for (int i = 1; i <= n / 2; i++) cout << b[i] << " " << a[i] << " ";
    36         cout << endl;
    37     }
    38 }
  • 相关阅读:
    django组件,有分页器(重要的很)
    wusir的django
    git 生成ssh key
    阶乘问题的题解
    拱猪计分的题解
    子数整数的题解
    安全逃离的题解
    题解 P1262 【间谍网络】
    斗地主的题解
    鸭王的题解
  • 原文地址:https://www.cnblogs.com/wangyiming/p/10130899.html
Copyright © 2011-2022 走看看