zoukankan      html  css  js  c++  java
  • Codeforces Round #366 (Div. 2)

      A题,水题。

      B题,博弈论题,找到的规律是当前数是奇数那么这个子游戏是必败的,否则必胜。那么异或一下即可。

      C题,模拟题,考虑到第三个操作如果之前清空到第x条,且当前清空到第t条,如果t比x要小,那么可以忽略清空到t条的操作;另外所有元素最多入队列和出队列一次。那么总的复杂度是O(n)的。代码如下:

     1 #include <stdio.h>
     2 #include <algorithm>
     3 #include <string.h>
     4 #include <string>
     5 #include <iostream>
     6 #include <queue>
     7 using namespace std;
     8 const int N = 300000 + 5;
     9 typedef long long ll;
    10 
    11 queue<int> Q[N];
    12 int tot;
    13 int vis[N];
    14 int who[N];
    15 
    16 int main()
    17 {
    18     int n,q;
    19     cin >> n >> q;
    20     int ans = 0;
    21     int now = 0;
    22     while(q--)
    23     {
    24         int a,b;
    25         scanf("%d%d",&a,&b);
    26         if(a == 1)
    27         {
    28             who[++tot] = b;
    29             Q[b].push(tot);
    30             ans ++;
    31         }
    32         else if(a == 2)
    33         {
    34             while(!Q[b].empty())
    35             {
    36                 int x = Q[b].front(); Q[b].pop();
    37                 ans --;
    38                 vis[x] = 1;
    39             }
    40         }
    41         else
    42         {
    43             for(int i=now+1;i<=b;i++)
    44             {
    45                 if(vis[i]) continue;
    46                 int t = who[i];
    47                 Q[t].pop();
    48                 ans --;
    49             }
    50             now = max(now, b);
    51         }
    52         printf("%d
    ",ans);
    53     }
    54     return 0;
    55 }
    C

      

      D题,题意蛮好理解的,但是有点繁琐。看了一下别人的博客说题目描述错误= =。难怪做的人这么少。

  • 相关阅读:
    python入门之函数及其方法
    Python入门知识点2---字符串
    Python列表 元组 字典 以及函数
    Python入门知识
    Autofac使用代码
    优化EF以及登录验证
    CRM框架小知识以及增删查改逻辑代码
    分页SQL
    触发器SQL
    动态生成lambda表达式
  • 原文地址:https://www.cnblogs.com/zzyDS/p/6388817.html
Copyright © 2011-2022 走看看