当前位置:网站首页>Leetcode game 295
Leetcode game 295
2022-06-09 08:55:00 【Shirandexiaowo】
summary
The conclusion is that you are too good , The monotonous stack needs more practice , Most of the time, monotone stack may not be the best value for simple maintenance . The second question focuses on library functions , The third question is the simple use of monotone stack , It was really not difficult after the game , But I don't know why I was crying when I was playing ~ Purring
6079. Price reduction
Not familiar with library functions hh, But I just learned . Because there was no special judgment, I sent another one
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. Make the array in non decreasing order
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. The minimum number of obstacles that need to be removed to reach the corner
// 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 = 200010, M = 300010;
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];
}
};
边栏推荐
- 49-oauth2 pkce configuration in authorization code
- Mobile terminal layout of Xiaomi official website
- SQL:市场分析 I
- Energy management and control system for industrial enterprises helps enterprises strengthen energy management and improve equipment operation efficiency
- EDA open source simulation tool verilator getting started 1: installation and testing
- Use Flashback Database and restore point
- Shell脚本批量对157台服务器打通网络、配置免密、重置root密码
- Written by shellcode
- SQL:体育馆的人流量(连续日期案例通用解决方案)
- 85. (leaflet house) leaflet military plotting - line arrow drawing
猜你喜欢

安科瑞配电室综合监控系统实现配电室内环境的在线监测,保障配电室设备的安全运行

Residual current relay uses residual current transformer to detect residual current and prevent electrical fire

工业企业能源管控系统帮助企业加强能源管理、提高设备运行效率

Written by shellcode

防火门监控系统对防火门状态进行24小时实时自动巡检

编辑器说明-备用

成本节省 50%,9人团队使用函数计算开发 wolai 在线文档应用

Openinfra summit 2022 𞓜 Android cloud users stand out and are shortlisted for the super user Award

.NET C#基础(6):命名空间 - 组织代码的利器

远程预付费管理系统帮助物业解决收费难统计难问题
随机推荐
10 个派上用场的 Flutter 小部件
Creation of JS class and use of constructor constructor
SQL: 重新格式化部门表 (行转列问题:Group by + 聚合函数)
Simple use of vim
Introduction to framework: the update expression is invalid. At least one column must be updated
.NET C#基础(6):命名空间 - 组织代码的利器
EDA open source simulation tool verilator getting started 1: installation and testing
Sql: capital gains and losses of stocks
防火门监控系统对防火门状态进行24小时实时自动巡检
Hj22 water bottle
汇编_常用指令
Clickhouse data type sorting of system operation and maintenance series
Acwing第 54 场周赛
3D programming mode: dependent isolation mode
Direct application of 10 kinds of question type explosive text title sentence patterns
修改市场活动表
RMAN backup concept_ About backup retention policy
剖析虚幻渲染体系(15)- XR专题
RMAN backup concept_ catalogue
85. (leaflet house) leaflet military plotting - line arrow drawing