acm之旅--湖南大学保研训练赛2

B - Spider Man

题目链接:B - Spider Man
参考博文:Codeforces-705B-Spider Man

  • 思路:可以根据数据知分解n,需要n-1次,则如果(n-1)是奇数,1胜,偶数,2胜。不断的测试,累加分解次数,然后再判断奇偶性即可。

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

const int MAX = 100005;
int a[MAX];

int main()
{
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for(int i=1; i<=n; i++)
    {
        scanf("%d", &a[i]);
        cnt += a[i]-1;
        if(cnt%2) printf("1\n");
        else      printf("2\n");
    }
    return 0;
}
C - Thor

题目链接:C - Thor
参考博文:CodeForces705C、Thor (STL)

  • 题目大意:有一个只能手机上有 n 个软件,这些软件会时不时产生一些未读信息。
    现在手机上发生了q 件事情,事情分为三类:
    软件 x 产生了一条未读信息。
    软件 x 的所有信息都被读了。
    前 t 条产生的信息都被读了。已读的也算在t条中。
    询问在每个事件发生后输出所有未读信息的总数。
  • 思路:用队列数组来维护每种信息当前有多少未读,再用一个数组按顺序记录收到的消息的类型。同时需要一定的优化技巧,比如记录第三类的信息被读数。

代码:

#include <iostream>
#include <cstdio>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
using namespace std;

const int MAX = 300005;
queue<int> q[MAX];
int val[MAX];//按顺序记录消息的类型
int n, q1, t, x;

int main()
{
    scanf("%d%d", &n, &q1);
    int cur = 0, ans = 0, next = 1;
    for(int i=1; i<=q1; i++)
    {
        scanf("%d%d", &t, &x);
        if(t==1)
        {
            cur++;
            ans++;
            val[cur] = x;
            q[x].push(cur);
            printf("%d\n", ans);
        }
        else if(t==2)
        {
            ans -= q[x].size();
            while(!q[x].empty()) q[x].pop();
            printf("%d\n", ans);
        }
        else if(t==3)
        {
            for(int j=next; j<=cur; j++)
            {
                if(next>x) break;//减枝,如果前x个已经读过
                int v = val[j];//第j的消息的类型
                next++;//前next个已经读过
                if(!q[v].empty() && q[v].front()<=x)//判断该范围内该类型是否存储未读消息
                {
                    ans--;
                    q[v].pop();
                }
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}
D - Ant Man

题目链接:D - Ant Man
参考博文:Codeforces 704B & 705D Ant Man

  • 思路:贪心算法,在区间中加点,如果一个点插在一个区间中比其他区间代价小,则为当前区间。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值