首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
主持人调度(一)
[编程题]主持人调度(一)
热度指数:2659
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
有 n 个活动即将举办,每个活动都有开始时间与活动的结束时间,第 i 个活动的开始时间是 start
i
,第 i 个活动的结束时间是 end
i
,举办某个活动就需要为该活动准备一个活动主持人。
一位活动主持人在同一时间只能参与一个活动。并且活动主持人需要全程参与活动,换句话说,一个主持人参与了第 i 个活动,那么该主持人在 (start
i
,end
i
) 这个时间段不能参与其他任何活动。请问一个只有一个主持人能否举办全部活动。
数据范围:
,
示例1
输入
[[0,10],[10,20],[20,30]]
输出
true
示例2
输入
[[0,10],[10,20],[15,30]]
输出
false
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(33)
分享
纠错
提交结果有问题?
13个回答
11篇题解
开通博客
unique琪殿
发表于 2023-07-23 17:35:13
解题要点(Java):①分别创建存放起始/终止时间的两个数组start/end,循环遍历原集合schedule,将各个时间存入。②使用Array.sort()对两个数组进行排序。③遍历,需始终满足下一个活动的起始时间晚于上一个活动的终止时间,才能返回true。代码实现: import java.ut
展开全文
这个算法非得学吗
发表于 2023-08-18 17:28:11
import java.util.*; public class Solution { public static boolean hostschedule(ArrayList<ArrayList<Integer>> schedule) { //先排序:
展开全文
写不来Algo
发表于 2025-01-15 23:07:24
一.题目解析题目还是很好理解的。目前只有一个主持人,但是有多个活动需要主持,如果这些活动时间互不牵扯,则主持人可以主持所有活动,返回true;反之活动时间交叉,则主持人无法主持所有活动,返回false二.算法原理第一次想到的就是,只要第二个活动的开始时间,大于等于前一场活动的结束时间就行了。但是有的
展开全文
君无颜
发表于 2022-03-25 18:47:06
实现思路:先排序,然后循环遍历,挨着和前面的比 如果出现的当前组的 end 比下一组的 start大,则返回false 如果循环正常结束,则没有问题,返回true 举例说明:[[0,10],[10,20],[15,30]] 其中[0,10]是第一组,0为第一组的start,10为第一组的end
展开全文
牛牛牛牛牛每一天
发表于 2023-12-12 17:12:17
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param schedule int整型二维数组 # @return bool布尔型 # class Solution: def hostschedule(self , schedule: L
展开全文
噜噜啦啦(✪▽✪)
发表于 2022-07-25 11:23:56
class Solution: def hostschedule(self , schedule: List[List[int]]) -> bool:
展开全文
姐姐的遮阳伞
发表于 2022-04-09 22:54:03
import java.util.*; public class Solution { public class ComparaActivities implements Comparator<ArrayList<Integer>> {
展开全文
犯困的火龙果快支棱起来
发表于 2024-05-20 16:44:08
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型vector<vector<>>
展开全文
南大一只牛
发表于 2023-04-26 09:46:27
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型ArrayList
展开全文
lanker
发表于 2025-03-28 19:44:18
#include <vector> class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型vector
展开全文
问题信息
排序
难度:
13条回答
33收藏
2977浏览
热门推荐
通过挑战的用户
查看代码
醉亦醒时醒亦醉
2022-09-24 13:43:07
牛客64148...
2022-09-21 16:42:42
牛客81838...
2022-09-21 16:16:34
牛客97702...
2022-09-15 17:16:13
就,很有意思
2022-09-14 20:28:46
相关试题
在下列表述中,错误的是()
字符串
树
排序
评论
(43)
如图 1 表示使用快表(页表)的虚...
编程基础
评论
(1)
对于我们来说,谁是好的顾客?
销售常识
评论
(1)
MySQL中执行 SELECT I...
SQL
评论
(1)
订单表order_table全部记...
查找
数据库
数据分析
SQL
评论
(2)
主持人调度(一)
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型ArrayList
> * @return bool布尔型 */ public boolean hostschedule (ArrayList
> schedule) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型vector
> * @return bool布尔型 */ bool hostschedule(vector
>& schedule) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param schedule int整型二维数组 # @return bool布尔型 # class Solution: def hostschedule(self , schedule ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型二维数组 * @return bool布尔型 */ public bool hostschedule (List
> schedule) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型二维数组 * @return bool布尔型 */ function hostschedule( schedule ) { // write code here } module.exports = { hostschedule : hostschedule };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param schedule int整型二维数组 # @return bool布尔型 # class Solution: def hostschedule(self , schedule: List[List[int]]) -> bool: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型二维数组 * @return bool布尔型 */ func hostschedule( schedule [][]int ) bool { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型二维数组 * @param scheduleRowLen int schedule数组行数 * @param scheduleColLen int* schedule数组列数 * @return bool布尔型 */ bool hostschedule(int** schedule, int scheduleRowLen, int* scheduleColLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param schedule int整型二维数组 # @return bool布尔型 # class Solution def hostschedule(schedule) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型二维数组 * @return bool布尔型 */ def hostschedule(schedule: Array[Array[Int]]): Boolean = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型二维数组 * @return bool布尔型 */ fun hostschedule(schedule: Array
): Boolean { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型二维数组 * @return bool布尔型 */ public boolean hostschedule (int[][] schedule) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型二维数组 * @return bool布尔型 */ export function hostschedule(schedule: number[][]): boolean { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型二维数组 * @return bool布尔型 */ func hostschedule ( _ schedule: [[Int]]) -> Bool { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param schedule int整型二维数组 * @return bool布尔型 */ pub fn hostschedule(&self, schedule: Vec
>) -> bool { // write code here } }
[[0,10],[10,20],[20,30]]
true
[[0,10],[10,20],[15,30]]
false