2 条题解

  • 0

    //
    #if 1

    //INCLUDE HEADERS
    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <string.h>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <map>
    #include <set>
    #include <list>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <memory.h>
    #include <sstream>
    //MACROS
    #define ll long long
    #define MAX 65535
    #define pause system("pause");
    #define debug printf("__DEBUG__\n");
    using namespace std;

    #define sigma 0.6180339887498949

    int main() {
    int n;
    cin >> n;
    vector<double>v;
    int x;
    for (int i = 0; i < n;++i)
    {
    cin >> x;
    v.push_back(x);
    v.push_back(x*sigma);
    }
    sort(v.begin(), v.end());

    int j = 0;
    double min = MAX;
    for (unsigned i = 1; i < v.size();++i)
    {
    if (v[i]-v[i-1]<min)
    {
    if ((int(v[i])==v[i])^(int(v[i-1])==v[i-1]))
    {
    min = v[i] - v[i - 1];
    j = i;
    }
    }
    }
    if (int(v[j])==v[j])
    {
    cout << v[j] <<endl << int(v[j - 1] / sigma) << endl;
    }
    else {
    cout << v[j - 1] << endl << int(v[j] / sigma) << endl;
    }

    return 0;
    }

    #endif

  • -1

    //
    #if 1

    //INCLUDE HEADERS
    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <string.h>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <map>
    #include <set>
    #include <list>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <memory.h>
    #include <sstream>
    //MACROS
    #define ll long long
    #define MAX 65535
    #define pause system("pause");
    #define debug printf("__DEBUG__\n");
    using namespace std;

    #define sigma 0.6180339887498949

    int main() {
    int n;
    cin >> n;
    vector<double>v;
    int x;
    for (int i = 0; i < n;++i)
    {
    cin >> x;
    v.push_back(x);
    v.push_back(x*sigma);
    }
    sort(v.begin(), v.end());

    int j = 0;
    double min = MAX;
    for (unsigned i = 1; i < v.size();++i)
    {
    if (v[i]-v[i-1]<min)
    {
    if ((int(v[i])==v[i])^(int(v[i-1])==v[i-1]))
    {
    min = v[i] - v[i - 1];
    j = i;
    }
    }
    }
    if (int(v[j])==v[j])
    {
    cout << v[j] <<endl << int(v[j - 1] / sigma) << endl;
    }
    else {
    cout << v[j - 1] << endl << int(v[j] / sigma) << endl;
    }

    return 0;
    }

    #endif

  • 1

信息

ID
1168
难度
7
分类
其他 | 二分查找 点击显示
标签
递交数
79
已通过
18
通过率
23%
上传者