cf1523C. Compression and Expansion
程序员文章站
2024-03-13 23:04:41
...
cf1523C. Compression and Expansion
题意:
让你模拟出一个书的目录,对于每一行给你一个数字,表示这个目录的最后一个数,
题解:
我们用vector存当前的目录情况,读到下一行,在尽量少删上一行的基础上,加入当前数字。而遇到1就以为这我们要单开一页(相当于目录层数增加)。然后直接模拟过程即可
代码:
#include <bits/stdc++.h>
#define rep(i, n) for (int i= 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
int main()
{
int t;
cin >> t;
while (t--) {
vector<int> v;
int n;
scanf("%d", &n);
rep(i, n)
{
int x;
scanf("%d", &x);
if (x > 1) {
while (!v.empty() && v.back() + 1 != x)
v.pop_back();
v.pop_back();
}
v.push_back(x);
rep(i, v.size())
{
if (i > 1)
putchar('.');
printf("%d", v[i - 1]);
}
puts("");
}
}
return 0;
}
推荐阅读
-
cf1523C. Compression and Expansion
-
cf.GCD Compression
-
CF 1370B GCD Compression
-
LeetCode 443. String Compression
-
443. String Compression
-
LeetCode443. String Compression
-
leetcode 443. String Compression
-
leetcode 443. String Compression
-
[leetcode]443. String Compression
-
[leetcode]443. String Compression