zoukankan      html  css  js  c++  java
  • CodeForces

    个人心得:周测题目,一题没出,难受得一批。这个题目做了一个半小时还是无限WR,虽然考虑到了二分答案这个点上面了,

    奈何二分比较差就想用自己的优化,虽然卡在了a=k*b+c,这里但是后面结束了这样解决还是超时了,看了一下网上的hash,思想一样

    但是却优化了很多,服气

    题目:

    You are given a sequence a consisting of n integers. Find the maximum possible value of  (integer remainder of ai divided by aj), 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.

    Example

    Input
    3
    3 4 5
    Output
    2
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<iomanip>
     6 #include<algorithm>
     7 using namespace std;
     8 #define inf 1<<29
     9 #define infa 2000000+10
    10 #define nu 50005
    11 int n,m;
    12 int book[infa];
    13 int main()
    14 {
    15     scanf("%d",&n);
    16     memset(book,-1,sizeof(book));
    17     int maxnum;
    18     for(int i=0;i<n;i++){
    19        scanf("%d",&m);
    20         book[m]=m;
    21     }
    22     for(int i=1;i<infa; i++)
    23         if(book[i]!=i)
    24         {
    25             book[i]=book[i-1];
    26         }
    27         int sum=0;
    28         for(int i=1;i<infa;i++)
    29         {
    30             if(book[i]==i)
    31                 {
    32                     for(int j=i*2-1;j<infa;j+=i)
    33                         sum=max(sum,book[j]%i);
    34                 }
    35         }
    36            cout<<sum<<endl;
    37     return 0;
    38 }
    View Code


  • 相关阅读:
    每日立会2015-11-30
    Some Modern Softwares' drawbacks: User experience 12/29/2015
    Sprint 5 summary: UI 界面更新,Azure端部署和用户反馈分析 12/28/2015
    Daily Scrum 12/25/2015
    Daily Scrum 12/24/2015
    Daily Scrum 12/23/2015
    Daily Scrum 12/21/2015
    Daily Scrum 12/18/2015
    Daily Scrum 12/17/2015
    Performance standard (ALPHA release) 12/17/2015
  • 原文地址:https://www.cnblogs.com/blvt/p/7867993.html
Copyright © 2011-2022 走看看