zoukankan      html  css  js  c++  java
  • poj- 2528 Mayor's posters

    Mayor’s posters

    Description

    The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for placing the posters and introduce the following rules:
    Every candidate can place exactly one poster on the wall.
    All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
    The wall is divided into segments and the width of each segment is one byte.
    Each poster must completely cover a contiguous number of wall segments.
    They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections.
    Your task is to find the number of visible posters when all the posters are placed given the information about posters’ size, their place and order of placement on the electoral wall.

    Input

    The first line of input contains a number c giving the number of cases that follow. The first line of data for a single case contains number 1 <= n <= 10000. The subsequent n lines describe the posters in the order in which they were placed. The i-th line among the n lines contains two integer numbers li and ri which are the number of the wall segment occupied by the left end and the right end of the i-th poster, respectively. We know that for each 1 <= i <= n, 1 <= li <= ri <= 10000000. After the i-th poster is placed, it entirely covers all wall segments numbered li, li+1 ,… , ri.

    Output

    For each input data set print the number of visible posters after all the posters are placed.
    The picture below illustrates the case of the sample input.

    Sample Input

    1
    5
    1 4
    2 6
    8 10
    3 4
    7 10

    Sample Output

    4
    题意:n(n<=10000) 个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000) 。求出最后还能看见多少张海报。
    思路:线段树+离散化 具体请参见 kuang_bin.bolg
    这个题怎么说?有点玄学我sum开int就过不去 , 线段树还必须开到1e5的8倍才能过,可是按理论应该是能过得,可能数据有问题
    AC code:

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <map>
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    
    using namespace std;
    
    const int maxn = 1e5+5;
    typedef long long ll;
    int vis[maxn];
    
    struct segtree{
        int l,r;
        bool sum;
    }ss[maxn<<3];
    
    struct Node{
        int l,r;
    }node[maxn];
    
    void pushUp(int rt){
        ss[rt].sum = ss[rt<<1].sum && ss[rt<<1|1].sum;
    }
    
    void build(int l,int r,int rt){
        ss[rt].l = l; ss[rt].r = r;
        ss[rt].sum = false;
        if(l == r) return;
        int mid = (l+r)>>1;
        build(lson); build(rson);
    }
    
    bool update(int l,int r,int rt){
        if(ss[rt].sum) return false;
        if ( ss[rt].l == l && ss[rt].r == r ) {
            ss[rt].sum = true; return true;
        }
        int mid = (ss[rt].l+ss[rt].r)>>1; bool res;
        if ( r<=mid ) {
            res = update(l,r,rt<<1);
        } else if ( mid<l ) {
            res = update(l,r,rt<<1|1);
        } else {
            bool res1 = update(lson);
            bool res2 = update(rson);
            res = res1||res2;
        }
        pushUp(rt);
        return res;
    }
    
    int main(){
        int t; cin>>t;
        while(t--)
        {
            int n; scanf("%d",&n); int pos = 0;
            for (int i = 0;i<n;i++) {
                scanf("%d %d",&node[i].l,&node[i].r);
                vis[++pos] = node[i].l ,vis[++pos] = node[i].r;
            }
            sort(vis+1,vis+pos+1);
            int len = unique(vis+1,vis+pos+1)-vis; len--;
            long long sum = 0; build(1,len,1);
            for (int i = n-1;i>=0;i--) {
                int l = lower_bound(vis+1,vis+len+1,node[i].l)-vis;
                int r = lower_bound(vis+1,vis+len+1,node[i].r)-vis;
                bool flag = update(l,r,1);
                if(flag) sum ++;
            }
            printf("%lld
    ",sum);
        }
        return 0;
    }
  • 相关阅读:
    科技巨头争抢的“超级账本”,到底是个什么组织?
    区块链结合教育,将给教育行业带来哪些变革?
    国家区块链战略开启,教育行业应对几何?
    区块链如何改变教育
    区块链技术在教育领域的应用模式与现实挑战
    知乎-区块链技术运用于教育有多少种可能?
    区块链+教育,让教育行业充满希望
    教育区块链应用案例【2019】
    区块链在教育行业的落地应用现状介绍
    PowerShell 搜索文件编码格式
  • 原文地址:https://www.cnblogs.com/Nlifea/p/11745967.html
Copyright © 2011-2022 走看看