• hdu 5071 vector操作恶心模拟


    http://acm.hdu.edu.cn/showproblem.php?pid=5071

    对于每一个窗口,有两个属性:优先级+说过的单词数,支持8个操作:新建窗口,关闭窗口并输出信息,聊天(置顶窗口加单词),把优先级最高的窗口移到最前,把当前第i个窗口移到最前,把选择的窗口移到最前,把某个窗口置顶,把置顶窗口取消置顶。。。最后按优先级输出每个窗口的优先级以及单词数。。。


    数据范围n<=5000…,恶心模拟

    主要就是vector的操作,开始的时候没有置顶窗口记得把now置为0,注意每个参数范围为10^9,要用long long 记录单词数

    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <queue>
    #include <stack>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define RD(x) scanf("%d",&x)
    #define RD2(x,y) scanf("%d%d",&x,&y)
    #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define clr0(x) memset(x,0,sizeof(x))
    typedef long long LL;
    typedef pair<int,LL> p2;
    vector<p2> p;
    int find(int x)
    {
        for(int i = 0;i < p.size();++i)
            if(p[i].first == x)
                return i;
        return -1;
    }
    void erase(int x)
    {
        int i = 0;
        for(vector<p2>::iterator it = p.begin();it != p.end();it++,i++){
            if(i == x){
                p.erase(it);return;
            }
        }
    }
    int x,now;
    void Add()
    {
        RD(x);
        if(-1 != find(x))
            puts("same priority.");
        else{
            p.push_back(make_pair(x,0));
            puts("success.");
        }
    }
    void Close()
    {
        RD(x);
        int cl = find(x);
        if(cl == -1)
            puts("invalid priority.");
        else{
            if(x == now)
                now = 0;
            printf("close %d with %I64d.
    ",p[cl].first,p[cl].second);
            erase(cl);
        }
    }
    void Chat()
    {
        RD(x);
        if(0 == p.size())
            puts("empty.");
        else{
            if(now)
                p[find(now)].second += x;
            else
                p[0].second += x;
            puts("success.");
        }
    }
    void Rotate(int y)
    {
        if(y < 1 || y > p.size())
            puts("out of range.");
        else{
            p2 erase_p = p[y - 1];
            erase(y - 1);
            p.insert(p.begin(),erase_p);
            puts("success.");
        }
    }
    void Prior()
    {
        int mx = 0,mx_i = -1;
        if(p.size() == 0)
            puts("empty.");
        else{
            for(int i = 0;i < p.size();++i)
                if(p[i].first > mx)
                    mx = p[i].first , mx_i = i;
            Rotate(mx_i + 1);
        }
    }
    void Choose()
    {
        RD(x);
        int ch = find(x);
        if(ch == -1)
            puts("invalid priority.");
        else
            Rotate(ch + 1);
    }
    void Top()
    {
        RD(x);
        if(find(x) == -1)
            puts("invalid priority.");
        else
            now = x,puts("success.");
    }
    void Untop()
    {
        if(now)
            now = 0,puts("success.");
        else
            puts("no such person.");
    }
    void Bye()
    {
        if(now){
            x = find(now);
            if(p[x].second != 0)
                printf("Bye %d: %I64d
    ",p[x].first,p[x].second);
            erase(x);
        }
        for(int i=0; i<p.size(); ++i)
            if(p[i].second)
                printf("Bye %d: %I64d
    ",p[i].first,p[i].second);
    }
    int main() {
        string op;
        int _,y,n;RD(_);while(_--){
            now = 0;
            RD(n);
            p.clear();
            for(int cas = 1;cas <= n;++cas){
                cin>>op;
                printf("Operation #%d: ",cas);
                if(op=="Add")
                    Add();
                else if(op=="Close")
                    Close();
                else if(op=="Chat")
                    Chat();
                else if(op=="Rotate")
                    RD(y),Rotate(y);
                else if(op=="Prior")
                    Prior();
                else if(op=="Choose")
                    Choose();
                else if(op=="Top")
                    Top();
                else if(op=="Untop")
                    Untop();
            }
            Bye();
        }
        return 0;
    }
    


  • 相关阅读:
    111
    ZeroClipBoard 复制粘贴插件
    三、新增临时素材
    二、获取AccessToken
    一、微信公众平台的接入微信公众平台的接入
    Jquery.validate的使用
    尝试解决IIS问题一些方法
    匿名类和匿名方法
    泛型类的认知
    发布支持mysql8.0的writer和reader
  • 原文地址:https://www.cnblogs.com/zibaohun/p/4049441.html
Copyright © 2020-2023  润新知