[UVA][段] 10587 - Mayor's posters@Morris' Blog|PChome Online 人新台
2014-02-17 09:22:27| 人2,094| 回0 | 上一篇 | 下一篇

[UVA][段] 10587 - Mayor's posters

0 收藏 0 0 站台

Problem G: Mayor's posters

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.

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 lili+1 ,... , ri.

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 

Output for sample input

4 

Author: Adapted from VI AMPwPZ by P. Rudnicki

目描述:


定每海的,按照序上去,求最後能看到海。

如果能看到同一海,被分到好地方,只能算看到一。

目解法:


需要散化,散化特小心,需要多散化一些,否有下方的。

#include <stdio.h>
#include <map>
#include <string.h>
using namespace std;
int Tree[1048576];
int query(int k, int l, int r, int ql, int qr) {
    if(l > r)    return 1;
    if(ql <= l && r <= qr)
        return Tree[k];
    if(Tree[k])    return 1;
    int m = (l + r)/2;
    if(m >= qr)
        return query(k<<1, l, m, ql, qr);
  &nsp; if(m < ql)
        return query(k<<1|1, m+1, r, ql, qr);
    return query(k<<1, l, m, ql, qr) &&
                query(k<<1|1, m+1, r, ql, qr);
}
void modify(int k, int l, int r, int ql, int qr) {
    if(l > r) {
        Tree[k] = 1;
        return;
    }
    if(ql <= l && r <= qr) {
        Tree[k] = 1;
        return ;
    }
    if(Tree[k])    return ;
    int m = (l + r)/2;
    if(m >= qr)
        modify(k<<1, l, m, ql, qr);
    else if(m < ql)
        modify(k<<1|1, m+1, r, ql, qr);
    else {
        modify(k<<1, l, m, ql, qr);
        modify(k<<1|1, m+1, r, ql, qr);
    }
    Tree[k] = Tree[k<<1]&Tree[k<<1|1];
}
int main() {
    int testcase, n;
    int i, j, k, L[10005], R[10005];
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%d", &n);
        map<int, int> RR;
        for(i = 0; i < n; i++) {
            scanf("%d %d", &L[i], &R[i]);
            RR[L[i]] = 1;
            RR[L[i]-1] = 1;
            RR[L[i]+1] = 1;
            RR[R[i]] = 1;
            RR[R[i]-1] = 1;
            RR[R[i]+1] = 1;
        }
        int size = 1;
        for(map<int, int>::iterator it = RR.begin();
            it != RR.end(); it++)
            it->secOnd= size++;
        memset(Tree, 0, sizeof(Tree));
        int ret = 0;
        for(i = n-1; i >= 0; i--) {
            int l = RR[L[i]], r = RR[R[i]];
            // printf("[%d, %d]\n", l, r);
            int v = query(1, 1, size, l, r);
            if(v == 0)
                ret++;
            modify(1, 1, size, l, r);
        }
        printf("%d\n", ret);
    }
    return 0;
}
/*
1
3
1 10
1 3
6 10

*/

台: Morris
人(2,094) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 教育(修、留、研究、教育概) | 人分: UVA |
此分下一篇:[UVA][剪枝] 10549 - Russian Dolls
此分上一篇:[UVA][] 10273 - Eat or Not to Eat

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86