问题一:

pi表示取第i个单,di表示送第i个单。di不能在pi的前面。给一个取单送单的顺序,问是否是valid顺序。

 public boolean isValidOrderList(List<String> list) {
Set<String> set = new HashSet<>();
for (String item : list) {
if (item.startsWith("P")) {
set.add(item);
} else {
String parent = getParent(item);
if (!set.contains(parent)) {
return false;
}
set.remove(parent);
}
}
return set.isEmpty();
} private String getParent(String dId) {
if (dId == null || dId.length() < || dId.charAt() != 'D') {
throw new IllegalArgumentException("invalid input:" + dId);
} int id = Integer.parseInt(dId.substring());
return "P" + id;
}

问题二:

pi表示取第i个单,di表示送第i个单。di不能在pi的前面。给一个n,显示所有正确的顺序。

 public List<List<String>> print(int n) {
List<List<String>> result = new ArrayList<>();
List<List<String>> tempList = new ArrayList<>();
for (int j = ; j <= n; j++) {
if (j == ) {
result.add(Arrays.asList("p1", "d1"));
continue;
}
for (int i = ; i < result.size(); i++) {
String[] temp = new String[j * ];
for (int p = ; p < * j; p++) {
for (int q = p + ; q < * j; q++) {
clearArray(temp);
temp[p] = "p" + j;
temp[q] = "d" + j;
fillInArray(result.get(i), temp);
tempList.add(arrayToList(temp));
}
}
}
result = new ArrayList<>(tempList);
tempList.clear();
} return result;
} private void clearArray(String[] arr) {
for (int i = ; i < arr.length; i++) {
arr[i] = null;
}
} private void fillInArray(List<String> result, String[] temp) {
int index = ;
for (String str : result) {
while(temp[index] != null) {
index++;
}
temp[index] = str;
}
} private List<String> arrayToList(String[] arr) {
List<String> list = new ArrayList<>();
for (String str : arr) {
list.add(str);
}
return list;
}

问题3:

给你一个数字,问你有多少种接单和送单的顺序。

比如

n = 1, only 1 possible, p1 d1

n = 2,  6 possible

p1 d1 p2 d2

p1 p2 d1 d2

p1 p2 d2 d1

p2 p1 d1 d2

p2 p1 d2 d1

p2 d2 p1 d1

 int totalCount(int n) {
if (n == ) return ;
int prevCount = ;
for (int i = ; i <= n; i++) {
int totalSlots = * i;
prevCount = sum(totalSlots - ) * prevCount;
}
return prevCount;
} int sum(int n) {
int total = ;
for (int i = ; i <= n; i++) {
total += i;
}
return total;
}

order pick-up and delivery problem的更多相关文章

  1. Order to Cash Process

    order to cash process steps can be listed as below · Enter the Sales Order · Book the Sales Order · ...

  2. Order&Shipping Transactions Status Summary

    Order&Shipping Transactions Status Summary Step Order Header Status Order Line Status Order Flow ...

  3. SPOJ ORDERSET - Order statistic set

    ORDERSET - Order statistic set   In this problem, you have to maintain a dynamic set of numbers whic ...

  4. How to Configure Nginx for Optimized Performance

    Features Pricing Add-ons Resources | Log in Sign up   Guides & Tutorials Web Server Guides Nginx ...

  5. Enhancing the Scalability of Memcached

    原文地址: https://software.intel.com/en-us/articles/enhancing-the-scalability-of-memcached-0 1 Introduct ...

  6. topcoder算法练习2

    Problem Statement      In most states, gamblers can choose from a wide variety of different lottery ...

  7. [SinGuLaRiTy] COCI 2011~2012 #2

    [SinGuLaRiTy-1008] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 测试题目 对于所有的题目:Time Limit:1s   ...

  8. (转)db2top详解

    原文:https://blog.csdn.net/lyjiau/article/details/47804001 https://www.ibm.com/support/knowledgecenter ...

  9. SD从零开始25-28

    SD从零开始25 装运的组织单元(Organizational Units in Shipping) 组织结构-后勤Organizational Structure-Logistics Plant在后 ...

随机推荐

  1. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  2. Gluon学习03-基础数据类型Ndarray

    Gluon学习03-基础数据类型Ndarray 小书匠 kindle  目录,方便快速定位: 1.安装cuda与cudnn 2.安装mxnet-gpu 本机环境介绍: 系统:Linuxmint Pyt ...

  3. 初步学习MySQL

    我们之前学习如何安装MySQL数据库 以及 navicat 管理数据库可视化工具 那么现在主要来学习一下如何使用,(操作数据库有很多方式,终端操作.可视化工具操作.编程语句操作) 我们首先学习在终端操 ...

  4. tomcat设置gzip

    使用tomcat发布3dtiles或terrain数据遇到的gzip问题 问题一 对大于1KB的json请求进行gzip压缩,json为原文件 1.创建原始文件 2.设置 在apache-tomcat ...

  5. Layui + 微信小程序 + PC端 + GatewayWorker + 移动端即时聊天系统

  6. 2018-2019-2 20165234 《网络对抗技术》 Exp7 网络欺诈防范

    Exp7  网络欺诈防范 实验内容 1. 简单应用SET工具建立冒名网站 2. ettercap DNS spoof 3. 结合应用两种技术,用DNS spoof引导特定访问到冒名网站 4. 请勿使用 ...

  7. vscode远程代码同步

    参考资料: https://blog.csdn.net/u012560340/article/details/83030680 https://github.com/liximomo/vscode-s ...

  8. HearthBuddy模拟对手的回合

    start calculations, current time: 10:29:48 V2019.09.01.002 Rush 10000 face 27 berserk:1 ets 200 secr ...

  9. 通过adb操作安卓亮屏、设置背光亮度、解锁、打开app

    亮屏 adb shell inputkeyevent 26 keyevent 26表示点击power Android adb 点亮和关闭屏幕的命令 # kernel休眠 echo mem > / ...

  10. usb 设备 复位

    How to Reset USB Device in Linux by ROMAN10 on MAY 4, 2011 · 9 COMMENTS   USB devices are anywhere n ...