• HDU 2275 Kiki & Little Kiki 1


    $map$,$set$。

    有可能有多个相同的数字,所以开一个$map$记录一下每个数字分别有几个,当$map[x]$减小到为$0$时,将$x$从$set$中删去。

    对于每一次询问,直接$lower$_$bound$找到第一个大于等于询问数字的地方,如果是$s.end()$,那么就输出上一个位置,如果值刚好等于询问的数字,那么直接输出。否则,也是输出上一个位置。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-6;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c = getchar();
        x = 0;
        while(!isdigit(c)) c = getchar();
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
    }
    
    int n;
    
    int main()
    {
        while(~scanf("%d",&n))
        {
            set<int>s;
            map<int,int>m;
    
            for(int i=1;i<=n;i++)
            {
                char op[10]; int x;
                scanf("%s%d",op,&x);
    
                if(op[1]=='u')
                {
                    if(m[x]==0) s.insert(x);
                    m[x]++;
                }
                else
                {
                    int xx=*s.begin();
                    if(s.size()==0) printf("No Element!
    ");
                    else if(xx>x) printf("No Element!
    ");
                    else
                    {
                        set<int>::iterator iter;
                        iter = s.lower_bound(x);
    
                        if(iter==s.end())
                        {
                            iter--;
                            int y=*iter;
                            m[y]--;
                            if(m[y]==0) s.erase(y);
                            printf("%d
    ",y);
                        }
                        else if(*iter==x)
                        {
                            int y=*iter;
                            m[y]--;
                            if(m[y]==0) s.erase(y);
                            printf("%d
    ",y);
                        }
                        else
                        {
                            iter--;
                            int y=*iter;
                            m[y]--;
                            if(m[y]==0) s.erase(y);
                            printf("%d
    ",y);
                        }
                    }
                }
            }
    
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    MVC 网页制作
    Mvc 中国直辖市下拉列表(三级联动)
    MVC 登陆注册页面
    MVC 数据库增删改查(Razor)视图(2)
    MVC 数据库增删改查(Razor)方法(1)和数据库
    winform网页抓取邮箱单发群发并有附件
    winform截取网页邮箱
    winform 图标表chart
    winform图片读取存储于数据库SQL
    winform计算器
  • 原文地址:https://www.cnblogs.com/zufezzt/p/6294195.html
Copyright © 2020-2023  润新知