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 ?
  • 相关阅读:
    社群电商
    文字超出部分省略号显示······
    jq监听页面的滚动事件,
    input 更改 pleaseholder 的字体样式
    20161213 scrapy安装
    map按照value排序的方法
    Qt跨线程信号和槽的连接
    C++ map指针的使用
    Python 高级进阶
    [转]解读C指针(5)——笔试题解析
  • 原文地址:https://www.cnblogs.com/hlmark/p/4081010.html
Copyright © 2011-2022 走看看