zoukankan      html  css  js  c++  java
  • CDOJ 1061 C

    Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu
    Appoint description: 

    Description

    男儿何不带吴钩,收取关山五十州。

    征战天下是秋实大哥一生的梦想,所以今天他又在练习一个对战游戏。

    秋实大哥命令所有士兵从左到右排成了一行来抵挡敌人的攻击。

    敌方每一次会攻击一个士兵,这个士兵就会阵亡,整个阵列就会从这个位置断开;同时有的时候已阵亡的士兵会受人赢气息感染而复活。

    秋实大哥想知道某一时刻某一个士兵所在的阵列的长度是多少。

    Input

    第一行包含两个整数nm,表示秋实大哥的士兵数目和接下来发生的事件数目。

    接下来m行,每一行是以下三种事件之一:

    0 x : 表示x位置的士兵受到攻击阵亡
    1 x : 表示x位置的士兵受人赢气息感染复活
    2 x : 秋实大哥想知道第x个士兵所在阵列的长度
    

    1nm1000001xn

    Output

    对于每一个2x事件,输出对应的答案占一行。

    Sample Input

    5 3 
    2 2 
    0 3 
    2 2

    Sample Output


    2

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <cmath>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <map>
    #include <algorithm>
    #include <set>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long Ull;
    #define MM(a,b) memset(a,b,sizeof(a));
    const double eps = 1e-10;
    const int inf = 0x3f3f3f3f;
    const double pi=acos(-1);
    const int maxn=100000;
    set<int> st;
    int main()
    {
        int n,m;
        while(~scanf("%d %d",&n,&m))
        {
            st.clear();
            st.insert(n+1);
            st.insert(0);
            //插入首尾两个位置
            int x,y;
            for(int i=1;i<=m;i++)
            {
                scanf("%d %d",&x,&y);
                if(!x)  st.insert(y);
                else if(x==1) st.erase(y);
                else if(x==2)
                {
                    if(st.count(y))
                        printf("0
    ");
                    else
                    {
                        set<int>::iterator itr=st.lower_bound(y),itl=itr;
                        itl--;
                        printf("%d
    ",*itr-*itl-1);
                    }
                }
            }
        }
        return 0;
    }
    

      分析:set的使用,set的迭代器可以自加自减但是无法进行迭代器之间的相加相减

  • 相关阅读:
    174. Dungeon Game
    240. Search a 2D Matrix II
    300. Longest Increasing Subsequence
    test markdown style
    多源多汇费用流——poj2516
    费用流消圈算法(构造残量网络)
    费用流模板(带权二分图匹配)——hdu1533
    最大流模板——进阶指南整理
    最大流任务调度+离散化——hdu2883
    最大流拆点——hdu2732,poj3436
  • 原文地址:https://www.cnblogs.com/smilesundream/p/5435166.html
Copyright © 2011-2022 走看看