第十四届蓝桥杯省赛C/C++大学B组真题-飞机降落


思路:根据数据范围N<=10猜测用DFS+剪枝,因为菜狗不会状压dp。根据题目,一般这种飞机的题都会用到贪心的思想。思想是每架飞机都要卡极限最早降落时间,从而保证后面的飞机能够有充足时间降落。
代码参考博客@MQy大佬有详细解答

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n;
struct Plane {
    int t, d, l;
}p[N];

bool vis[N];
bool dfs(int pos, int last){
    if(pos == n) return true;
    for(int i = 0; i < n; ++i){
        int t = p[i].t, d = p[i].d, l = p[i].l;
        if(!vis[i] && t + d >= last){
            vis[i] = true;
            if(dfs(pos + 1, max(last, t) + l)) return true;
            vis[i] = false;
        }
    }
    return false;
}

int main(void){
    int T;
    cin >> T;

    while(T--){
        scanf("%d", &n);
        for(int i = 0; i < n; ++i){
            int t, d, l;
            scanf("%d%d%d", &t, &d, &l);
            p[i] = {t, d, l};
        }

        memset(vis, 0, sizeof vis);
        if(dfs(0,0)) puts("YES");
        else puts("NO");
    }

    return 0;
}
相关推荐
初願致夕霞14 小时前
C++11:类型推导与完美转发复盘笔记
c++
小猪写代码14 小时前
C++中什么是类,什么是对象
c++
Navigator_Z16 小时前
LeetCode //MySQL - 1251. Average Selling Price
c语言·算法·leetcode
Escalating_xu17 小时前
【C语言数据类型和变量·上】从内置类型到变量模型:一次讲透 sizeof、signed/unsigned 与作用域
c语言
钓鱼的肝18 小时前
梳理(1-5)
c++·经验分享·笔记·算法·青少年编程
aramae18 小时前
模拟实现strlen()函数 (C语言)
c语言·开发语言·后端
jimy119 小时前
readelf 查看“派生类”的vtable符号
开发语言·c++
蒸蒸yyyyzwd19 小时前
cpp 选手秋招学习笔记 day37 面经学习
c++·八股
YYYing.20 小时前
【C++进阶系列 (七)】C++ RTTI 深度剖析:从 typeid 到 dynamic_cast 的底层之旅
开发语言·c++·c/c++·rtti
多弗朗皮卡丘20 小时前
数据结构9:排序算法
c语言·数据结构·排序算法