LeetCode 第 295 场周赛

LeetCode 第 295 场周赛总结 总结就是自己太菜了哇 单调栈要去多练一练 很多时候单调栈可能不是简单维护最值了 第二题主要考察了库函数 第三题就是单调栈的简单运用叭 赛后感觉确实不难 但是不知道为什么会被比赛时的自己蠢哭 呜呜呜 6079 价格减免 对库函数不太熟叭 hh 不过正好学到了 因为没有特判然后就又寄了一发 class

大家好,我是讯享网,很高兴认识大家。

总结

总结就是自己太菜了哇,单调栈要去多练一练,很多时候单调栈可能不是简单维护最值了。第二题主要考察了库函数,第三题就是单调栈的简单运用叭,赛后感觉确实不难,但是不知道为什么会被比赛时的自己蠢哭~呜呜呜


讯享网

6079. 价格减免

对库函数不太熟叭hh,不过正好学到了。因为没有特判然后就又寄了一发

class Solution { 
    public: long long check(string s) { 
    if (s.empty()) return false; for (auto & c : s) if (!isdigit(c)) return false; return stoll(s); } string discountPrices(string s, int d) { 
    stringstream ss(s); string str; string ans; while (ss >> str) { 
    ans += " "; if (str[0] != '$') { 
    ans += str; continue; } else { 
    long long t = check(str.substr(1)); if (t) { 
    char c[20] = { 
   }; cout << t << endl; sprintf(c, "$%.2lf", (double)t * 1.0 * (100 - d) / 100); ans += c; } else ans += str; } } return ans.substr(1); } }; 

讯享网

6080. 使数组按非递减顺序排列

讯享网class Solution { 
    public: int totalSteps(vector<int> &nums) { 
    int ans = 0; stack<pair<int, int>> st; for (int num : nums) { 
    int maxT = 0; while (!st.empty() && st.top().first <= num) { 
    maxT = max(maxT, st.top().second); st.pop(); } if (!st.empty()) ++maxT; ans = max(ans, maxT); st.emplace(num, maxT); } return ans; } }; 

6081. 到达角落需要移除障碍物的最小数目

// shiran #include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for (int i = a; i < n; i++) #define per(i, n, a) for (int i = n - 1; i >= a; i--) #define sz(x) (int)size(x) #define fi first #define se second #define all(x) x.begin(), x.end() #define pb push_back #define mk make_mair typedef long long ll; typedef pair<int, int> PII; const int INF = 1e9+7; const int N = , M = ; int dx[4] = { 
   -1, 0, 1, 0}, dy[4] = { 
   0, 1, 0, -1}; struct Node { 
    int x, y, d; bool operator< (const Node &t) const { 
    return d > t.d; } }; class Solution { 
    public: int minimumObstacles(vector<vector<int>>& grid) { 
    int n = grid.size(), m = grid[0].size(); vector<vector<int>> f(n, vector<int>(m, INF)); priority_queue<Node> q; q.push({ 
   0, 0, 0}); f[0][0] = 0; while (q.size()) { 
    auto t = q.top(); q.pop(); if (t.x == n - 1 && t.y == m - 1) break; rep(i, 0, 4) { 
    int x = t.x + dx[i], y = t.y + dy[i]; if (x < 0 || x >= n || y < 0 || y >= m) continue; if (f[x][y] > f[t.x][t.y] + grid[x][y]) { 
    f[x][y] = f[t.x][t.y] + grid[x][y]; q.push({ 
   x, y, f[x][y]}); } } } return f[n - 1][m - 1]; } }; 
小讯
上一篇 2025-04-06 22:18
下一篇 2025-01-19 11:57

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/57363.html