Day 5 jzoj4309. 【NOIP2015模拟11.4】刷题计划

Description

这里写图片描述

Input

这里写图片描述

Output

这里写图片描述

Sample Input

10000 12
2 1
3
2 9999
3
1 1
3
2 1
3
2 10000
3
2 9999
3

Sample Output

1
9999 1
9999
9999
10000 9999
9999 10000

做法: 暴力模拟即可

代码如下:

#include <cstdio>
#include <cstring>
#include <iostream>
#define N 270
#define rep(i, a, b)    for (int i = a; i <= b; i++)
#define dep(i, a, b)    for (int i = a; i >= b; i--)
#define ll long long
using namespace std;
ll n, m, a[N], s[N], st, tot;
ll x, y;

void print()
{
    tot = 0;
    rep(i, 1, m + 3)
        if (a[i] != 0 && tot < 20)  cout << a[i] << " ", tot++;
    cout << endl;
}

int main()
{
    freopen("problem.in", "r", stdin);
    freopen("problem.out", "w", stdout);
    cin >> n >> m;
    rep(p, 1, m)
    {
        cin >> x;
        if (x == 3) print();
        else
        {
            cin >> y;
            if (x == 1)
            {
                bool b = 1;
                rep(i, 1, st)
                    if (s[i] == y)  b = 0;
                if (b)  s[++st] = y;
                rep(i, 1, m + 10)
                    if (a[i] == y)  a[i] = 0;
            }
            else if (x == 2)
            {
                bool b = 1;
                rep(i, 1, st)
                    if (s[i] == y)  b = 0;
                if (!b) continue;
                int j = 0;
                rep(i, 1, m + 3)
                    if (a[i] == y)  a[i] = 0;
                rep(i, 1, m + 3)
                    if (a[i] != 0)
                    {
                        j = i;
                        break;
                    }
                if (j == 0) j = m + 3;
                a[j - 1] = y;
            }
        }
    }
    fclose(stdin);
    fclose(stdout); 
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值