zoukankan      html  css  js  c++  java
  • Codesforces 485D Maximum Value

                                                      D. Maximum Value
     

    You are given a sequence a consisting of n integers. Find the maximum possible value of  (integer remainder of ai divided byaj), where 1 ≤ i, j ≤ n and ai ≥ aj.

    Input

    The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).

    The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).

    Output

    Print the answer to the problem.

    Sample test(s)
    input
    3
    3 4 5
    output
    2

    给出 n 个数 a[0] ~ a[n-1] ,要你找出 a[i] % a[j] 最大.

    处理一个数组x[i]表示 1~i 离i最近的数是什么。就可以过了。

    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long LL;
    const int mod = (1e9+7);
    const int N = 2000010;
    bool num[N];
    int x[N] , a;
    int main()
    {
        int n ;
        cin >> n ;
        for( int i = 0 ; i < n ; ++i ) {
            cin >> a;
            num[a] = 1 ;
        }    
        for( int i = 0 ; i <= 2e6 ; ++i ){
            if( num[i] )x[i] = i ;
            else x[i] = x[i-1] ;
        }
        int res = 0  ;
        for( int i = 1 ; i <= 1e6 ; ++i ) if( num[i] ){ 
            for( int j = 2 * i ; j <= 2e6 ; j += i ) {
                res = max( res , ( x[j-1] ) % i );
            }
        }
        cout << res << endl;
    }
    View Code
    only strive for your goal , can you make your dream come true ?
  • 相关阅读:
    expect简介和使用例子(转)
    openshift网络
    openstack相关
    SDN的开源方案sonic
    OpenStack Neutron ML2 Deep Dive
    2017双11技术揭秘—阿里数据库计算存储分离与离在线混布
    es的gui工具
    django orm中blank和null的区别
    断关联多表关系阐述
    视图使用
  • 原文地址:https://www.cnblogs.com/hlmark/p/4081010.html
Copyright © 2011-2022 走看看