首页 > 其他分享 >AtCoder Beginner Contest 273(E)

AtCoder Beginner Contest 273(E)

时间:2023-06-13 21:35:46浏览次数:43  
标签:AtCoder include Beginner int cin 273 op now define

AtCoder Beginner Contest 273(E)

E(链式结构,思维)

E

题目大意就是原本有一个空的序列,我们后面会进行\(q\)次操作,每次操作我们都需要输出此时的序列的最后数字

下面有几种操作

\(ADD\) \(x\),代表在这在这个序列的最后面添加一个\(x\)

\(DELETE\),代表如果此时的序列存在数字的话,那么我们就移除最后一个数字

\(SAVE\) \(y\),把此时的序列记录在一个题目中给出的一个\(page_y\)

\(LOAD\) \(z\):把此时的序列变成在\(page_z\)里面保存的序列里面

我之前是想过用\(map<int,vector< int >>\),但是它\(re\)了

我\(ac\)的解法用的是链式结构

我们先用一个\(now\)随着每次操作的标记

添加一个数字,我们会在数组里面添加上\(x\),而且我们还会保存此时的\(now\)标记,这样我们后面在实现保存\(page\)和获取\(page\)里面的数组,我们每次保存就是保存\(now\),后面假如我们需要用到用到\(page\),我们就会调用里面的标记\(now\),然后把这个值赋给此时的\(now\),同样删除一个数字就是把当前的\(now\)赋给它的上一个\(now\)

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include<cmath>
#include <unordered_map>
#include <array>
#include <cstring>
#include <bitset>
#include <numeric>
using namespace std;
#define int long long 
#define LL long long
#define ios  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define inf 1e18
#define INF 1e18
#define eps 1e-6
#define mem(a,b) memset((a),(b),sizeof(a))
const int maxn=5e5+10;
const int mod=998244353;
int q;
map<int,int>bk;
vector<pair<int,int>>res;
int now;
signed main ()
{
  ios;
  cin>>q;
  res.push_back({0,-1});
  now=0;
  while (q--)
  {
    string op;
    cin>>op;
    if(op=="ADD")
    {
      int x;
      cin>>x;
      res.push_back({now,x});
      now=res.size()-1;
    }
    else if(op=="DELETE")
    {
      now=res[now].first;
    }
    else if(op=="SAVE")
    {
      int x;
      cin>>x;
      bk[x]=now;
    }
    else if(op=="LOAD")
    {
      int x;
      cin>>x;
      now=bk[x];
    }
    cout<<res[now].second<<" ";
  }
  system ("pause");
  return 0;
}

标签:AtCoder,include,Beginner,int,cin,273,op,now,define
From: https://www.cnblogs.com/righting/p/17478754.html

相关文章

  • AtCoder Beginner Contest 265 F Manhattan Cafe
    洛谷传送门AtCoder传送门考虑dp,\(f_{i,j,k}\)表示考虑到第\(i\)维,\(\sum\limits_{x=1}^i|p_x-r_x|=j,\sum\limits_{x=1}^i|q_x-r_x|=k\)的方案数。转移是容易的,枚举\(r_i\)即可,\(f_{i,j,k}=\sum\limits_rf_{i-1,j-|p_i-r|,k-|q_i-r|}......
  • Atcoder Beginner Contest 301
    A-OverallWinner题目大意A和T两人玩游戏,给定一串只由A和T组成的字符串,如果第i个字符是A,则A赢得第i轮的胜利,反之则T赢;当遍历完整个字符串后,谁赢的轮数多谁就是最终赢家,如果一样则谁最先达到该轮数谁赢,输出赢家的名字解题思路签到题不多嗦了神秘代码......
  • AtCoder Beginner Contest 278 ABCDE
    AtCoderBeginnerContest278A-ShiftProblemStatement题意:给你一个长度为n的序列,让你移走前面k个后面补k个0。Solution思路:按照题意模拟即可。#include<bits/stdc++.h>usingnamespacestd;inta[1100];intmain(){ intn,k; cin>>n>>k; k=min(k,n); for(int......
  • UNIQUE VISION Programming Contest 2023 New Year (AtCoder Beginner Contest 287) A
    UNIQUEVISIONProgrammingContest2023NewYear(AtCoderBeginnerContest287)A-MajorityProblemStatement题意:给你n个字符串,字符串是For表示agree,字符串Against表示disagree,让你判断最终是否通过。Solution思路:统计For和Against的数量,比较一下即可。#include......
  • AtCoder Beginner Contest 284 ABCDE
    AtCoderBeginnerContest284A-SequenceofStringsProblemStatement题意:给你n个字符串,让你倒序输出Solve#include<bits/stdc++.h>usingnamespacestd;constintN=20;strings[N];intmain(){ intn; cin>>n; for(inti=1;i<=n;i++) cin>>s......
  • Atcoder-AGC033C
    看到这道题,是个博弈论,没见过树上的,于是想到在数列里的博弈论,又联想到树的特殊形式————链。于是我们来讨论一下链的情况(对于没有硬币的点,我们就视为它被删掉了):讨论链的情况发现若是选择两端的点,顶点数会减一;若是选择中间的点,顶点数会减二。现在我们站在链的角度来思考......
  • AtCoder Beginner Contest 302
    A-Attack题目大意给定两个数a和b,问我们需要进行多少次a-b,才能让a小于等于0解题思路签到题不多嗦了神秘代码#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintN=1e6+10;signedmain(){inta,b,c;cin>>a>>b;if(a%b......
  • HDU 2732 Leapin' Lizards(最大流)
    题意:给你一个网格,网格上的一些位置上有一只蜥蜴,所有蜥蜴的最大跳跃距离是d,如果一只蜥蜴能跳出网格边缘,那么它就安全了.且每个网格有一个最大跳出次数x,即最多有x只蜥蜴从这个网格跳出,这个网格就再也不能有蜥蜴进来了.问你最少有多少只蜥蜴跳不出网格.思路:和POJ3498差不多.........
  • AtCoder Beginner Contest 305 题解
    https://atcoder.jp/contests/abc305/tasks_printE-ArtGalleryonGraph冷知识:md这题赛时没做出来/cy刚看到题:这是什么题啊,\(K,h\)都\(1e5\)能做吗/fn确实能做。考虑类似SPFA的操作。设\(a_x\)表示\(x\)还可以对距离最多为\(a_x\)的点产生贡献,然后就直接......
  • AtCoder Beginner Contest 258 F Main Street
    洛谷传送门AtCoder传送门发现这题有个远古的WA就来改了(发现走法很多种,不想分类讨论,考虑最短路。设起点编号为\(1\),终点为\(11\)。\(x=Bn\)和\(y=Bn\)把坐标系分成了若干块。考虑过起点作一条平行于\(Ox\)的直线,与左右两条\(x=Bn\)的线有两个交点,给它们编号......