zoukankan      html  css  js  c++  java
  • POJ 3263 差分+set判重

    题意:
    这里写图片描述
    这里写图片描述
    思路:
    对于每一个区间 [a,b] [a+1,b-1]肯定是比a,b低至少1的
    因为题目要求最大值
    所以就直接差分一下 搞之
    (复杂度 O(n))
    Discuss里说有重复的数据
    用set判一下重就好了复杂度O(nlogn)

    //By SiriusRen
    #include <set>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int N,I,H,R,xx,yy,s[10050],tmp,ans[10050];
    set<int>st;
    int main(){
        scanf("%d%d%d%d",&N,&I,&H,&R);
        for(int i=1;i<=R;i++){
            scanf("%d%d",&xx,&yy);
            if(st.find(xx*10000+yy)==st.end()){
                st.insert(xx*10000+yy);
                if(xx>yy)swap(xx,yy);
                s[xx+1]--,s[yy]++;
            }
        }
        for(int i=0;i<N;i++){
            tmp+=s[(I+i)%N+1];
            ans[(I+i)%N+1]=tmp+H;
        }
        for(int i=1;i<=N;i++){
            printf("%d
    ",ans[i]);
        }
    }

    这里写图片描述

  • 相关阅读:
    【HDOJ】1811 Rank of Tetris
    【HDOJ】1518 Square
    日期类 Date
    RunTime
    System 系统类
    StringBuffer
    获取联系人列表的时候contact_id出现null的值
    String类
    object类
    eclipse使用的步骤
  • 原文地址:https://www.cnblogs.com/SiriusRen/p/6532260.html
Copyright © 2011-2022 走看看