• B


    https://vjudge.net/contest/394066#problem/B

    https://vjudge.net/problem/Gym-102082B/origin

    数据量大不能用数组查

    用了二分,在test57的地方OT了,应该是算法有问题(待补题

    附未通过代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <cctype>
    #include <cmath>
    #include <cstdlib>
    #include <ctime>
    #include <deque>
    #include <iomanip>
    #include <list>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <vector>
    #include <iterator>
    #include <utility>
    #include <sstream>
    #include <limits>
    #include <numeric>
    #include <functional>
    using namespace std;
    #define gc getchar()
    #define mem(a) memset(a,0,sizeof(a))
    #define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl;
    
    #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    typedef long long ll;
    typedef unsigned long long ull;
    typedef long double ld;
    typedef pair<int,int> pii;
    typedef char ch;
    typedef double db;
    
    const double PI=acos(-1.0);
    const double eps=1e-6;
    const int inf=0x3f3f3f3f;
    const int maxn=1e5+10;
    const int maxm=100+10;
    const int N=1e6+10;
    const int mod=1e9+7;
    
    
    
    
    ll a[5005] = {0};
    bool find(ll key ,ll n)
    {
        int left = 1,right = n;
        while(left <= right)
        {
            int mid = (left + right) / 2;
            if(a[mid] == key)
                return 1;
            else if(a[mid] > key)
                right = mid - 1;
            else
                left = mid + 1;
        }
        return 0;
    }
    
    
    int main()
    {
        ll n = 0;
        cin >> n;
        for(ll i = 0;i<n;i++)
        {
            cin >> a[i];
        }
        sort(a,a+n);
    
        ll max = 0;
        for(ll i = 0;i<n-1;i++)
        {
            for(ll j = i+1;j<n;j++)
            {
                ll counter = 0;
                ll x = a[i] > a[j] ? a[i] : a[j];
                ll y = a[i] < a[j] ? a[i] : a[j];
                ll d = x - y;
                ll temp = x + d;
                while(find(temp,n) && temp <= 1e9)
                {
                    temp += d;
                    counter += 1;
                }
                //cout<<x << " "<<y<<" "<<counter<<endl;
                if(counter > max)max = counter;
            }
        }
        cout << max+2;
        return 0;
    }
    

      

  • 相关阅读:
    BlockQueue学习笔记
    XZ文件压缩解压(转)
    github/gitee:fork别人的源码仓库并contribute代码
    Git安装配置
    整合MyBatisPlus
    Vue模块化开发
    前端小知识
    Node.js 安装配置
    Maven安装配置
    服务器上数据库被删优化办法
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13695743.html
Copyright © 2020-2023  润新知