zoukankan      html  css  js  c++  java
  • hdu 5265 pog loves szh II

    函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置。如果所有元素都小于val,则返回last的位置

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    typedef unsigned long long ull;
    
    int main()
    {
        __int64 n,p,a[100000+5],ans;
        __int64 *t;
        int i,j;
        while(~scanf("%I64d%I64d",&n,&p))
        {
            for(i=0; i<n; i++)
            {
                scanf("%I64d",&a[i]);
                a[i]%=p;
            }
            sort(a,a+n);
            ans=(a[n-1]+a[n-2])%p;
            for(i=0; i<n; i++)
            {
                t=lower_bound(a,a+i,p-a[i]);
                if(t!=a+i&&t!=a)
                {
                    ans=max(ans,a[i]+*(t-1));
                }
                if(ans==p-1) break;
            }
            printf("%I64d
    ",ans);
    
        }
        return 0;
    }
    

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    电子商务测试点总结
    pc 端 测试点总结
    web测试点总结
    Monkey脚本API
    Git 命令
    配置samba的流程
    scrapy使用指南
    链接
    顺序表总结
    python数据类型——字符串类型
  • 原文地址:https://www.cnblogs.com/xryz/p/4847959.html
Copyright © 2011-2022 走看看