FZU 2091 播放器

题目地址:http://acm.fzu.edu.cn/problem.php?pid=2091

用一个大数组存播放列表,同时记录当前播放的曲号(dq)和播放列表末尾的曲号(*mw);

也可以用栈进行操作;

按照题目要求进行相应操作即可;

AC代码:

#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int x[10000+500+10];
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        memset(x,0,sizeof(x));
        int m,n;
        cin>>n>>m;
        x[1]=1;
        int dq=1;//记录当前的曲号
        int *mw=&x[1];//记录播放列表末尾的曲号
        while(m--)
        {
            string c;
            cin>>c;
            //模拟播放器操作
            if(c=="PRE")
            {
                if(mw!=&x[1])
                {
                    *mw=0;
                    mw--;
                    dq=*mw;
                }
                else dq=1;
            }
            else if(c=="PLAY")
            {
                int q;
                cin>>q;
                dq=q;
            }
            else if(c=="NEXT")
            {
                if(dq!=n)
                {
                    dq++;
                }
            }
            //播放列表末尾和当前播放的曲目不同时添加到播放列表末尾
            if(dq!=*mw)
                {
                    mw++;
                    *mw=dq;
                }
            cout<<dq<<endl;
        }
    }
}

相关日志

  1. 2016.05.04

    FZU 2041 checker(搜索)

    题目链接:http://acm.fzu.ed…

  2. 2016.05.12

    ZOJ 3698 Carrot Fantasy(搜索大模拟)

    题目地址:http://acm.zju.ed…

  3. 2016.07.10

    Codeforces Round #361 (Div. 2)A. Mike and Cellphone

    果然CF是三亿coder的coding梦想(…

  4. 2016.07.13

    安利一波答案 经典算法设计

      (更多…)

  5. 2016.05.09

    FZU 2093 寻找兔子(状压dp)

    题目地址:http://acm.fzu.ed…

  6. 2016.07.10

    Codeforces Round #361 (Div. 2)B. Mike and Shortcuts

    题意迷之简短。大意就是:一个城市i到另一个城…

评论

还没有评论。

在此评论中不能使用 HTML 标签。