UNIQUE VISION Programming Contest 2024 Autumn (AtCoder Beginner Contest 372)

总结(我的塘人局):

单调栈是忘得差不多了 

A - delete .

题意:

输出删除所有'.'的字符串

思路:

遍历输出不是'.'

复杂度:

O(n) 

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
     
using namespace std;
using LL = long long;
using i64 = int64_t;
 
void solve() {
    string s;
    cin >> s;
    for (char c : s) {
        if (c != '.') cout << c;
    }
}
 
int main() {
    cin.tie(0) -> sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

  

B - 3^A

题意:

给定一个一个M找到长度为n数组a[]满足(

且一定存在一个序列满足

 

 

思路:

通过贪心从最大的3 ^ i开始减去,直至M被分解完成

复杂度:

O(M)

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <bits/stdc++.h>
     
using namespace std;
using LL = long long;
using i64 = int64_t;
constexpr int N = 22;
int pre[N], m;
 
void solve() {
    cin >> m;
    int idx = 0;
    vector <int> ver;
    for ( ; m > 0;) {
        idx = 0;
        while (m >= pre[idx + 1] && idx <= 9) {
            idx++;
        }
        ver.push_back(idx);
        m -= pre[idx];
    }
    cout << ver.size() << '\n';
    for (int i : ver) cout << i << ' ';
}
 
int main() {
    cin.tie(0) -> sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    for (int i = 0; i < 11; i++) pre[i] = pow(3, i);
    while (t--) {
        solve();
    }
    return 0;
}

  

D - Buildings

类似力扣的一题:

1944. 队列中可以看到的人数 - 力扣(LeetCode)

posted @   Iter-moon  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
点击右上角即可分享
微信分享提示