每日两题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;
}
相关推荐
dazzle18 小时前
机器学习算法原理与实践-入门(三):使用数学方法实现KNN
人工智能·算法·机器学习
那个村的李富贵18 小时前
智能炼金术:CANN加速的新材料AI设计系统
人工智能·算法·aigc·cann
张张努力变强19 小时前
C++ STL string 类:常用接口 + auto + 范围 for全攻略,字符串操作效率拉满
开发语言·数据结构·c++·算法·stl
万岳科技系统开发19 小时前
食堂采购系统源码库存扣减算法与并发控制实现详解
java·前端·数据库·算法
小镇敲码人19 小时前
探索CANN框架中TBE仓库:张量加速引擎的优化之道
c++·华为·acl·cann·ops-nn
张登杰踩19 小时前
MCR ALS 多元曲线分辨算法详解
算法
平安的平安19 小时前
面向大模型算子开发的高效编程范式PyPTO深度解析
c++·mfc
June`19 小时前
muduo项目排查错误+测试
linux·c++·github·muduo网络库
C++ 老炮儿的技术栈19 小时前
VS2015 + Qt 实现图形化Hello World(详细步骤)
c语言·开发语言·c++·windows·qt
YuTaoShao19 小时前
【LeetCode 每日一题】3634. 使数组平衡的最少移除数目——(解法一)排序+滑动窗口
算法·leetcode·排序算法