Codeforces 190C(模拟)

坑点

  • 不记它难解我心头之恨……
  • WA1:不要读错题Orz,顺序是按它给定的。那就是个类似栈的东西,重点在于输出。
  • 然而我输出很快就模拟对了……
  • WA2:数据:1 int。我日了不看数据我真的去de模拟的bug了。
  • WA3:中间栈空是非法。
  • 貌似建一棵树可以迅速搞掉……擦
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

const int maxn = 1e5 + 5;
int n, m, cnt, flag, mark[maxn], go, last[maxn];
string s;
vector<string> v;
int p[maxn][2], x = 1;

void print(int now) {
    cout << "pair<";
    if (p[now][0] > 0)  print(p[now][0]);
    else    cout << "int";
    cout << ",";
    if (p[now][1] > 0)  print(p[now][1]);
    else    cout << "int";
    cout << ">";
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    while (cin >> s) {
        if (s == "pair") {
            if (!m) {
                go = ++m;
                mark[go] = 0;
                cnt += 2;
                continue;
            }
            if (cnt == 0)   flag = 1;
            cnt++;
            p[go][mark[go]] = ++m;//pair
            mark[go] ^= 1;
            last[m] = go;
            go = m;
        } else {
            if (cnt == 0)   flag = 1;
            cnt--;
            p[go][mark[go]] = -1;//int
            mark[go] ^= 1;
            while (go && mark[go] == 0) go = last[go];
        }
    }
    if (m == 0 && n == 1) {//淦
        cout << "int"; return 0;
    }
    if (cnt || flag) {
        cout << "Error occurred";
    } else {
        print(x);
    }
}
// pair pair int pair int int pair int int

原文地址:https://www.cnblogs.com/AlphaWA/p/10952129.html

时间: 2024-08-28 22:04:22

Codeforces 190C(模拟)的相关文章

CodeForces - 427B (模拟题)

Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of t

CodeForces - 404B(模拟题)

Marathon Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose

Codeforces 452D [模拟][贪心]

题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的衣服或者烘干的衣服较多来不及进行下一个步骤,则从一开始就顺延洗衣服的时间,贪心的思想也是体现在这里. 3.关键在于烘干衣服的顺延如何处理,因为需要调整洗衣服的起始时间,其实我们只要对烘干衣服的时间进行顺延处理就可以了,因为即使没有调整洗衣服的起始时间,那么下次到了烘干衣服的时间的时候因为烘干衣服的数

CodeForces - 404A(模拟题)

Valera and X Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the Engli

CodeForces - 200ACinema模拟题

CodeForces - 200A Cinema Time Limit: 1500MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The capital of Berland has the only movie theater in the country. Besides, it consists of only one room. The room is divid

CodeForces 190C STL

Portal: http://codeforces.com/problemset/problem/190/C 一道卡输入输出的蛋疼题 题意:给你一个由pair和int所组成的沙茶字符串(最大含有1e5个单词),输出合法的pair序列 这道题可以拿栈做,也就是vector或stack 呵呵 (vector==stack)=1 Examples Input 3pair pair int int int Output pair<pair<int,int>,int> 1 #include&

【题解】Berland.Taxi Codeforces 883L 模拟 线段树 堆

Prelude 题目传送门:ヾ(?ω?`)o Solution 按照题意模拟即可. 维护一个优先队列,里面装的是正在运营中的出租车,关键字是乘客的下车时间. 维护一个线段树,第\(i\)个位置表示第\(i\)个房子前面有没有停放出租车,这样在有人需要打车的时候可以快速找到离她最近的车的位置. 对每个房子维护一个堆,里面装的是停在这个房子前面的出租车,关键字是出租车的编号和上一个乘客下车的时间,上一个乘客下车越早,等待时间越长. 然后模拟时间的流逝就可以了,代码非常好写. Code #includ

CodeForces - 864C-Bus-(模拟加油站问题)

https://vjudge.net/problem/CodeForces-864C 题意:两地之间有个加油站,往返走k个单程,最少加油多少次. 大佬几十行代码就解决,我却要用一百多行的if语句模拟解决. #include<stdio.h> #include<iostream> #include<algorithm> #include<cstring> #include<math.h> #include<string> #includ

Codeforces 703B (模拟) Mishka and trip

题目:这里 题意:n个城市,每个城市有个魅力值vi,首先,有n条路将这n个城市连成一个环,1号城市连2号城市,2号连3号****n号连1号城市,每条路的魅力值是其连接的两个城市 的魅力值的乘积,这n个城市其中还有k个是特殊城市,每个特殊城市和任意一条城市都有一条路连接,看题目下面的图,保证每两个城市之间最多只有一条路,问所有路的 魅力值之和是多少? 首先是连接成环的路线魅力值,很好算,然后每个特殊城市的路线,先求出所有城市的魅力值之和sum,依次求特殊城市的时候用sum减去这个特殊城市本身以及两