蓝桥3511飞机降落
样例输入
2
3
0 100 10
10 10 10
0 2 20
3
0 10 20
10 10 20
20 10 20
样例输出
YES
NO
思路:
具体来说,对于每架飞机,有起飞时间(t)、降落时间限制(d)和飞行时长(l)等信息,代码要判断能否按照一定规则安排这些飞机的起降顺序,使得所有飞机都能在其降落时间限制内完成降落。
代码展示:
#include<bits/stdc++.h>
using namespace std;
int n;
const int N = 20;
bool st[N];
struct plane {
int t, d, l;
}p[N];
bool dfs(int u, int time)
{
if (u >= n) return true;
for (int i = 0; i < n; i++)
{
if (!st[i])
{
st[i] = true;
if (p[i].t + p[i].d < time)
{
st[i] = false;
return false;
}
int t = max(time, p[i].t) + p[i].l;
if (dfs(u + 1, t)) return true;
st[i] = false;
}
}
return false;
}
void solve()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> p[i].t >> p[i].d >> p[i].l;
}
if (dfs(0, 0)) cout << "YES" << endl;
else cout << "NO" << endl;
for (int i = 0; i < n; i++)
st[i] = false;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现