zoukankan      html  css  js  c++  java
  • Codeforces Round #667 (Div. 3) E. Two Platforms

    题意:数轴上n个点,用两根长len的线段覆盖尽量多的点,求点数
    (原题面可谓花里胡哨)

    最初的想法,预处理每个数为起点和终点能覆盖到的长度,然后枚举起点,在前面做一次RMQ,大概是在O(nlogn)的

    练车的时候发现不需要每次搞RMQ(有点像蓝书),动态维护前面的最大值就行,O(n)扫一遍

    /*
     * Author	: GhostCai
     * Date		: 2020.09.04
     * Time		: 22:47:38
    
       Expecto Patronum
    
    */
    
    #include<bits/stdc++.h>
    
    using namespace std;
    
    inline int rd(){
    	int ret=0,f=1;char c;
    	while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;
    	while(isdigit(c))ret=ret*10+c-'0',c=getchar();
        return ret*f;
    }
    
    #define pc putchar
    #define space() pc(' ')
    #define nextline() pc('
    ')
    void pot(int x){if(!x)return;pot(x/10);pc('0'+x%10);}
    void out(int x){if(!x)pc('0');if(x<0)pc('-'),x=-x;pot(x);}
    
    const int MAXN = 200005;
    
    int x[MAXN];
    
    int solve(){
        int n,len;
        n=rd();len=rd();
        for(int i=1;i<=n;i++)x[i]=rd();
        for(int i=1;i<=n;i++) rd();//useless though
        sort(x+1,x+1+n);
    	int ans=0,premax=0;
        for(int i=1,j=1,k=1;i<=n;i++){
            while(x[i]+len>=x[j]&&j<n) j++;
    		if(x[i]+len<x[j])j--;
    		while(i-1&&x[k]<x[i-1]-len&&k<i-1) k++;
    		premax=max(premax,(i-1)-k+1);
    		ans=max(ans,premax+j-i+1);
        }
    	return ans;
    }
    
    int main(){
        int T=rd();
        while(T--) cout<<solve()<<endl;
        return 0;
    }
    
  • 相关阅读:
    深度学习
    !gcc !vi
    条件、循环及其他语句
    当索引行不通时
    我的排班日期
    Linux使用storcli工具查看服务器硬盘和raid组信息
    storcli64和smartctl定位硬盘的故障信息
    Shell-四剑客
    iostat
    /VAR/LOG/各个日志文件分析
  • 原文地址:https://www.cnblogs.com/ghostcai/p/13622527.html
Copyright © 2011-2022 走看看