每日两题day67

今天你AC了吗?

每日两题day67


一、基础题

题目:P1567 统计天数 - 洛谷

思路:

代码:

cpp 复制代码
#include <bits/stdc++.h>

int main() {
    int n, days = 1, r = 1;
    std::cin >> n;
    std::vector<int> a(n);
    std::cin >> a[0];
    for (int i = 1; i < n; i++) {
        std::cin >> a[i];
        if (a[i] > a[i - 1]) {
            days++;
            r = std::max(r, days);
        } else {
            days = 1;
        }
    }
    std::cout << r;
    return 0;
}

二、提高题

题目:P1135 奇怪的电梯 - 洛谷

思路:

bfs,从A按层序搜到B,注意特判A==B。

代码:

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if (a == b) {
        cout << 0 << "\n";
        return 0;
    }
    vector<int> t(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
    }
    queue<int> q;
    vector<int> u(n + 1);
    u[a] = 1;
    q.push(a);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        int l = x - t[x], r = x + t[x];
        if (l > 0 && u[l] == 0) {
            if (b == l) {
                cout << u[x] << "\n";
                return 0;
            }
            q.push(l);
            u[l] = u[x] + 1;
        }
        if (r <= n && u[r] == 0) {
            if (b == r) {
                cout << u[x] << "\n";
                return 0;
            }
            q.push(r);
            u[r] = u[x] + 1;
        }
    }
    cout << "-1\n";
    return 0;
}
相关推荐
白狐_7984 分钟前
408数据结构第5章:树与二叉树②——遍历、线索树、森林与哈夫曼
数据结构·算法·深度优先
zh路西法15 分钟前
【3D SLAM源码解读系列】(二)Small_gicp——5 个积木搭出最优点云配准
c++·pcl·icp·fastgicp·smallgicp·gicp
fpcc2 小时前
ubuntu26环境下的开发环境安装处理
c++·并行编程
致Great3 小时前
科研人的 AI,不该只回答问题:我用字节TraeWork 跑了一遍真实研究任务
算法
纵有疾風起3 小时前
线性表的定义与基本操作 — 从逻辑结构到 ADT 接口
数据结构·算法·408·线性表·adt
charlie1145141914 小时前
Cinux · 第一次跳进 Ring 3:用户态与特权隔离
开发语言·c++·操作系统·开源项目
别动我齐刘海4 小时前
机器学习基础2——C++、OpenCV、点云、Open3D
c++·人工智能·opencv·机器学习·计算机视觉·机器人·ros2
测试_AI_一辰4 小时前
AI Agent 评测最隐蔽的坑-记忆
人工智能·算法·ai·自动化·ai编程
躺不平的理查德4 小时前
Windows C++ 第三方库使用流程备忘录--OpenCV
开发语言·c++
余额瞒着我当琳4 小时前
C++STL容器string--迭代器,string的接口,string的遍历,访问方式
c++