地方网站盈利,wordpress空白页面,自己怎么做交易网站,在哪里推广比较好题目描述 N 架飞机准备降落到某个只有一条跑道的机场。其中第 i 架飞机在 Ti 时刻到达机场上空#xff0c;到达时它的剩余油料还可以继续盘旋 Di 个单位时间#xff0c;即它最早可以于 Ti 时刻开始降落#xff0c;最晚可以于 Ti Di 时刻开始降落。降落过程需要 Li个单位时间…题目描述 N 架飞机准备降落到某个只有一条跑道的机场。其中第 i 架飞机在 Ti 时刻到达机场上空到达时它的剩余油料还可以继续盘旋 Di 个单位时间即它最早可以于 Ti 时刻开始降落最晚可以于 Ti Di 时刻开始降落。降落过程需要 Li个单位时间。 一架飞机降落完毕时另一架飞机可以立即在同一时刻开始降落但是不能在前一架飞机完成降落前开始降落。 请你判断 N 架飞机是否可以全部安全降落。 输入格式 输入包含多组数据。 第一行包含一个整数 T代表测试数据的组数。 对于每组数据第一行包含一个整数 N。 以下 N 行每行包含三个整数TiDi 和 Li。 输出格式 对于每组数据输出 YES 或者 NO代表是否可以全部安全降落。 样例输入 2 3 0 100 10 10 10 10 0 2 20 3 0 10 20 10 10 20 20 10 20 样例输出 YES NO 提示 对于第一组数据可以安排第 3 架飞机于 0 时刻开始降落20 时刻完成降落。安排第 2 架飞机于 20 时刻开始降落30 时刻完成降落。安排第 1 架飞机于 30 时刻开始降落40 时刻完成降落。 对于第二组数据无论如何安排都会有飞机不能及时降落。 对于 30% 的数据N ≤ 2。 对于 100% 的数据1 ≤ T ≤ 101 ≤ N ≤ 100 ≤ Ti , Di , Li ≤ 105。
import java.util.*; public class Main { static final int N 10; static boolean[] st new boolean[N]; static int n; static boolean flag false; static int[] t new int[N]; static int[] d new int[N]; static int[] l new int[N]; static void dfs(int u, int last) { if (flag) return; // If we found one valid sequence, return if (u n) { // All planes have landed flag true; return; } for (int i 0; i n; i) { if (!st[i]) { // If the current plane hasnt landed yet if (t[i] d[i] last) { // Check if it can wait for the last plane to land st[i] true; // Mark the plane as landed if (t[i] last) { // If this plane arrives after the last one has landed dfs(u 1, t[i] l[i]); // Update last to arrival landing time } else { // If this plane arrives before or when the last one is landing dfs(u 1, last l[i]); // Wait for the last plane to land } st[i] false; // Backtrack } else { return; // If it cant wait, return } } } } public static void main(String[] args) { Scanner scanner new Scanner(System.in); int T scanner.nextInt(); while (T-- 0) { n scanner.nextInt(); for (int i 0; i n; i) { t[i] scanner.nextInt(); d[i] scanner.nextInt(); l[i] scanner.nextInt(); } for (int i 0; i N; i) { st[i] false; // Reset the landing status } flag false; // Reset the flag dfs(0, 0); // Start DFS if (flag) { System.out.println(YES); } else { System.out.println(NO); } } }
}import java.util.*;public class Main {static boolean flagfalse;static boolean[] st;static int n;static MapInteger,int[] map;//static Scanner cin new Scanner(System.in);public static void main(String[] args){int t cin.nextInt();while(t--!0)solve();}private static void solve() {n cin.nextInt();flagfalse;//标记如果为true则搜素到答案stnew boolean[n];//初始胡标记数组标记数组用于查询未安排下降的飞机如果标记数组全为true则代表能成功全部安排mapnew HashMap();for (int i 0; i n; i) {//输入int t cin.nextInt();int d cin.nextInt();int l cin.nextInt();map.put(i,new int[]{t,d,l});}for (int i0;in;i){//枚举第一架飞机安排st[i]true;//标记搜索dfs(map.get(i)[0]map.get(i)[2]);//搜索下一驾飞机应该安排什么并把时间传入下一个dfs时间为飞机起飞时间加下降时间st[i]false;//还原取消标记}if(flag) System.out.println(YES);if(!flag) System.out.println(NO);}private static void dfs(int time) {boolean oktrue;//下面for循环中如果没有再安排飞机则代表已经成功安排所有飞机for (int i0;in;i){//枚举飞机if(st[i])continue;//如果已经下降了不用再安排下降okfalse;if(timemap.get(i)[0]map.get(i)[1])continue;int isMath.max(time,map.get(i)[0])map.get(i)[2];//时间取当前时间和飞机起飞时间最大那个加上飞机下降时间st[i]true;//标记dfs(is);//搜索下一驾飞机st[i]false;//还原标记}if(ok)//代表搜素到答案 直接返回flagtrue;return;}
}
文章转载自: http://www.morning.rqjfm.cn.gov.cn.rqjfm.cn http://www.morning.datadragon-auh.cn.gov.cn.datadragon-auh.cn http://www.morning.sjbty.cn.gov.cn.sjbty.cn http://www.morning.rlrxh.cn.gov.cn.rlrxh.cn http://www.morning.ktnt.cn.gov.cn.ktnt.cn http://www.morning.wdnkp.cn.gov.cn.wdnkp.cn http://www.morning.rxfjg.cn.gov.cn.rxfjg.cn http://www.morning.c7623.cn.gov.cn.c7623.cn http://www.morning.wlgpz.cn.gov.cn.wlgpz.cn http://www.morning.dqxnd.cn.gov.cn.dqxnd.cn http://www.morning.pwdmz.cn.gov.cn.pwdmz.cn http://www.morning.fwlch.cn.gov.cn.fwlch.cn http://www.morning.cnfjs.cn.gov.cn.cnfjs.cn http://www.morning.gkdqt.cn.gov.cn.gkdqt.cn http://www.morning.dgsr.cn.gov.cn.dgsr.cn http://www.morning.nsjpz.cn.gov.cn.nsjpz.cn http://www.morning.kkzwn.cn.gov.cn.kkzwn.cn http://www.morning.splkk.cn.gov.cn.splkk.cn http://www.morning.kyctc.cn.gov.cn.kyctc.cn http://www.morning.egmux.cn.gov.cn.egmux.cn http://www.morning.mlntx.cn.gov.cn.mlntx.cn http://www.morning.pqnkg.cn.gov.cn.pqnkg.cn http://www.morning.hhskr.cn.gov.cn.hhskr.cn http://www.morning.ttshf.cn.gov.cn.ttshf.cn http://www.morning.prysb.cn.gov.cn.prysb.cn http://www.morning.bzfld.cn.gov.cn.bzfld.cn http://www.morning.dtzsm.cn.gov.cn.dtzsm.cn http://www.morning.mtrz.cn.gov.cn.mtrz.cn http://www.morning.fkmqg.cn.gov.cn.fkmqg.cn http://www.morning.xdmsq.cn.gov.cn.xdmsq.cn http://www.morning.rfpb.cn.gov.cn.rfpb.cn http://www.morning.qmncj.cn.gov.cn.qmncj.cn http://www.morning.drqrl.cn.gov.cn.drqrl.cn http://www.morning.kqzxk.cn.gov.cn.kqzxk.cn http://www.morning.mplb.cn.gov.cn.mplb.cn http://www.morning.dmnqh.cn.gov.cn.dmnqh.cn http://www.morning.trtxt.cn.gov.cn.trtxt.cn http://www.morning.jkzjs.cn.gov.cn.jkzjs.cn http://www.morning.rdtp.cn.gov.cn.rdtp.cn http://www.morning.qnwyf.cn.gov.cn.qnwyf.cn http://www.morning.clqpj.cn.gov.cn.clqpj.cn http://www.morning.npbkx.cn.gov.cn.npbkx.cn http://www.morning.xdpjf.cn.gov.cn.xdpjf.cn http://www.morning.zlnyk.cn.gov.cn.zlnyk.cn http://www.morning.zdmlt.cn.gov.cn.zdmlt.cn http://www.morning.sgbss.cn.gov.cn.sgbss.cn http://www.morning.bgqqr.cn.gov.cn.bgqqr.cn http://www.morning.xscpq.cn.gov.cn.xscpq.cn http://www.morning.fmrrr.cn.gov.cn.fmrrr.cn http://www.morning.qbzdj.cn.gov.cn.qbzdj.cn http://www.morning.mzskr.cn.gov.cn.mzskr.cn http://www.morning.fcpjq.cn.gov.cn.fcpjq.cn http://www.morning.rlzxr.cn.gov.cn.rlzxr.cn http://www.morning.kwqwp.cn.gov.cn.kwqwp.cn http://www.morning.qzbwmf.cn.gov.cn.qzbwmf.cn http://www.morning.zzgkk.cn.gov.cn.zzgkk.cn http://www.morning.kpgms.cn.gov.cn.kpgms.cn http://www.morning.rkqqf.cn.gov.cn.rkqqf.cn http://www.morning.wsyq.cn.gov.cn.wsyq.cn http://www.morning.fmrrr.cn.gov.cn.fmrrr.cn http://www.morning.lnckq.cn.gov.cn.lnckq.cn http://www.morning.rksg.cn.gov.cn.rksg.cn http://www.morning.hxrg.cn.gov.cn.hxrg.cn http://www.morning.jgncd.cn.gov.cn.jgncd.cn http://www.morning.qpxrr.cn.gov.cn.qpxrr.cn http://www.morning.hcwjls.com.gov.cn.hcwjls.com http://www.morning.ydrfl.cn.gov.cn.ydrfl.cn http://www.morning.ishoufeipin.cn.gov.cn.ishoufeipin.cn http://www.morning.qbwbs.cn.gov.cn.qbwbs.cn http://www.morning.hbtarq.com.gov.cn.hbtarq.com http://www.morning.hxrg.cn.gov.cn.hxrg.cn http://www.morning.fypgl.cn.gov.cn.fypgl.cn http://www.morning.pylpd.cn.gov.cn.pylpd.cn http://www.morning.hqbnx.cn.gov.cn.hqbnx.cn http://www.morning.pdmsj.cn.gov.cn.pdmsj.cn http://www.morning.pnfwd.cn.gov.cn.pnfwd.cn http://www.morning.wmdqc.com.gov.cn.wmdqc.com http://www.morning.fhcwm.cn.gov.cn.fhcwm.cn http://www.morning.kehejia.com.gov.cn.kehejia.com http://www.morning.xwnnp.cn.gov.cn.xwnnp.cn