当前位置:网站首页>Force buckle 1024 video splicing
Force buckle 1024 video splicing
2022-06-28 08:16:00 【wy_ forty-three million four hundred and thirty-one thousand ei】
1、1024. Video splicing
Source force deduction analysis :1024 Try to solve the problem
Medium difficulty 261
You'll get a series of video clips , These fragments come from an item with a duration of time Sports events in seconds . These fragments may overlap , It may also be of different lengths .
Using arrays clips Describe all the video clips , among clips[i] = [starti, endi] Express : A video clip starts at starti And in endi end .
You can even freely re edit these clips :
- for example , fragment
[0, 7]It can be cut into[0, 1] + [1, 3] + [3, 7]In the third part of .
We need to re edit these clips , And then the edited content is spliced into a segment covering the whole motion process ([0, time]). Returns the minimum number of fragments required , If you can't do it , Then return to -1 .
Example 1:
Input :clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10
Output :3
explain :
Choose [0,2], [8,10], [1,9] These three clips .
then , Remake the game clips as follows :
take [1,9] Then edit it as [1,2] + [2,8] + [8,9] .
Now the clip in hand is [0,2] + [2,8] + [8,10], And these cover the whole game [0, 10].
Example 2:
Input :clips = [[0,1],[1,2]], time = 5
Output :-1
explain :
You can't just [0,1] and [1,2] Cover [0,5] The whole process .
Example 3:
Input :clips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], time = 9
Output :3
explain :
Select segment [0,4], [4,7] and [6,9] .
Example 4:
Input :clips = [[0,4],[2,8]], time = 5
Output :2
explain :
Be careful , You may record a video longer than the end of the game .
analysis
First sort all videos in ascending order according to the start time. If the start time is the same, then sort them in descending order according to the end time
In this way, we greedily choose every interval as long as possible
Code
class Solution {
public int videoStitching(int[][] clips, int time) {
if(time== 0) return 0;
Arrays.sort(clips,(a,b)->{
if(a[0]==b[0]){
return a[1]-b[1];
}
return a[0]-b[0];
});
int count=0;
int i=0,n=clips.length;
int cur_end=0,next_end=0;
while(i<n && clips[i][0]<=cur_end){
while(i<n && clips[i][0]<=cur_end){
next_end=Math.max(next_end,clips[i][1]);
i++;
}
count++;
cur_end=next_end;
if(cur_end>=time) return count;
}
return -1;
}
}
边栏推荐
猜你喜欢

Set the icon for the title section of the page

22/02/15 study notes

Devops foundation chapter Jenkins deployment (II)

小艺人黄鑫洋受邀参加巴黎时装周儿童单元武汉站

Children's unit of 2022 Paris fashion week ended successfully at Wuhan station on June 19

2022第六季完美童模 佛山赛区 初赛圆满落幕

Do you know TCP protocol (1)?

After installing NRM, the internal/validators js:124 throw new ERR_ INVALID_ ARG_ TYPE(name, ‘string‘, value)

The preliminary round of the sixth season of 2022 perfect children's model Foshan competition area came to a successful conclusion

Reverse mapping of anonymous pages
随机推荐
Prometheus deployment alarm docking QQ mailbox
【尚品汇】项目笔记
sql主從複制搭建
js运算符的优先级
Study notes 22/1/19 and 22/1/20
2022第六季完美童模 佛山赛区 初赛圆满落幕
ROS notes (09) - query and setting of parameters
PMP从报考到拿证基本操作,了解PMP必看篇
AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0
Host is not allowed to connect to this MySQL server
图像翻译/Transformer:ITTR: Unpaired Image-to-Image Translation with Transformers用Transfor进行非配对图像对图像的转换
Activity隐式跳转
ROS 笔记(08)— 服务数据的定义与使用
Configuring multiple instances of MySQL under Linux
Study notes 22/1/18
How to choose an account opening broker? Is it safe to open an account online?
新唐NUC980使用记录:自制开发板(基于NUC980DK61YC)
三角变换公式
Upgrade HDP spark to spark 2.4.8 without upgrading ambari
你了解TCP协议吗(一)?