第十四届蓝桥杯省赛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;
}
相关推荐
·present·11 小时前
CSAPP(lecture 4_01)
c语言·c++
FPGA小迷弟11 小时前
用 Claude Code 重构遗留系统:从评估到落地的完整实践指南
c++·python·ai·plotly·django·ai编程·claude
程序员-King.12 小时前
【ROS1】Noetic 开发工作流程与常用命令
c++·ubuntu·ros
云深麋鹿12 小时前
C++ | 基于红黑树实现mymap与myset
开发语言·c++
傲世仙尊13 小时前
string增删查改-insert-erase-replace与find加substr组合技
c++
·present·15 小时前
CSAPP(lecture 3)
c++
本地化文档15 小时前
llvm-libc-docs-l10n
c语言·github·gitcode·sphinx·llvm·crowdin
别动我齐刘海15 小时前
机器人 C++ / 系统联调补强2——异常处理、Protobuf
linux·c++·人工智能·学习·算法·机器学习·机器人
basketball61615 小时前
C++ 中字符串与常见类型的转换总结
开发语言·c++
等我调个Bug16 小时前
C++智能指针通俗讲解
开发语言·c++