zoukankan      html  css  js  c++  java
  • Cake Robbery

    Cake Robbery
    Time Limit: 2000 msMemory Limit: 65536 KB

    As usual, Alice finishes her delicious cake at noon. Unfortunately, the smell of cake beckoned hungry Bob, and he decided to rob one piece of cake.

    The cake is a convex polygon with N edges. At the beginning, Bob cut it along the diagonals. After M cuts, Bob decided to rob the 'largest' piece of cake. Strangely, in Bob's opinion, the piece has the most number of edge is the biggest one.

    Please help Bob to find the 'largest' piece.

    Input

    There are multiple test cases (about 20).

    The first line of each test case contains two integer number NM (5 <= N <= 10000), indicating the number of point of the cake and the cut, respectively.

    The following M lines contain two integer x, y (1 <= x, y <= N), denoting the index of the starting and ending cut point. (the index of points mark from 1 to Nclockwise.)

    The input will guarantee that all of the cuts will not intersect inside the cake, but they may cross each other at the edge of cake, and Bob won't cut along the initial edge of the cake.

    Output

    Output the maximal size (most number of edges) of the piece which Bob will get.

    Sample Input

    7 2
    3 6
    7 2
    

    Sample Output

    4
    #include<bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    const int maxn = 2e5 + 50;
    
    struct cake {
        int l, r;
    
        inline void get() {
            scanf("%d%d", &l, &r);
            if (l > r)swap(l, r);
        }
    
        bool operator<(const cake &cur) const {
            return r - l + 1 <= cur.r - cur.l + 1;
        }
    } o[maxn];
    
    
    struct tree {
        int l, r, cnt;
    } e[maxn];
    
    inline void build(int rt, int l, int r) {
        e[rt].l = l;
        e[rt].r = r;
        e[rt].cnt = r - l + 1;
        if (l == r)return;
        int mid = l + r >> 1;
        build(rt << 1, l, mid);
        build(rt << 1 | 1, mid + 1, r);
    }
    
    inline void update(int ql, int qr, int rt) {
        int l = e[rt].l;
        int r = e[rt].r;
        if (ql <= l && qr >= r) {
            e[rt].cnt = 0;
            return;
        }
        int mid = l + r >> 1;
        if (ql <= mid) {
            update(ql, qr, rt << 1);
        }
        if (qr > mid) {
            update(ql, qr, rt << 1 | 1);
        }
        e[rt].cnt = e[rt << 1].cnt + e[rt << 1 | 1].cnt;
    }
    
    
    int n, m;
    
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("1.txt", "r", stdin);
    #endif
        while (scanf("%d%d", &n, &m) != EOF) {
            for (register int i = 1; i <= m; ++i) {
                o[i].get();
            }
            sort(o + 1, o + 1 + m);
            build(1, 1, n);
            int res = 0, tot = e[1].cnt;
            for (register int i = 1; i <= m; ++i) {
                update(o[i].l + 1, o[i].r - 1, 1);
                res = max(res, tot - e[1].cnt + 2);
                tot = e[1].cnt;
            }
            res = max(res, e[1].cnt);
            printf("%d
    ", res);
        }
        return 0;
    }
  • 相关阅读:
    微信外包就找北京动点飞扬软件(长年承接开发微信服务号,订阅号)
    北京动点飞扬软件招募【Android全职工程师】
    win8外包公司——技术分享:参数传递
    微软官方的Windowsphone社区
    Windowsphone8外包团队——wp8控件学习资源整理
    Android外包团队——Jquery乱码解决方案
    Flex外包公司——Flex案例展示
    Flex外包公司——案例汇总
    FLEX外包团队:Flex例子DEMO源码
    flex外包团队—北京动点软件:推荐一本不错的Flex书籍
  • 原文地址:https://www.cnblogs.com/czy-power/p/11487982.html
Copyright © 2011-2022 走看看