当前位置:网站首页>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;
}
}
边栏推荐
- Trigonometric transformation formula
- NPM clean cache
- Understanding of CUDA, cudnn and tensorrt
- Children's unit of 2022 Paris fashion week ended successfully at Wuhan station on June 19
- 抗洪救灾,共克时艰,城联优品捐赠10万元爱心物资驰援英德
- B_ QuRT_ User_ Guide(26)
- 券商注册开户靠谱吗?安全吗?
- 2022第六季完美童模 佛山赛区 初赛圆满落幕
- 找合适的PMP机构只需2步搞定,一查二问
- Unity 获取当前物体正前方,一定角度、距离的坐标点
猜你喜欢

B_QuRT_User_Guide(28)

Jenkins' common build trigger and hook services (V)

Activity implicit jump

ROS 笔记(09)— 参数的查询和设置

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

你了解TCP协议吗(一)?

Prometheus deployment alarm docking QQ mailbox
![[learning notes] matroid](/img/e3/4e003f5d89752306ea901c70230deb.png)
[learning notes] matroid

城联优品向英德捐赠抗洪救灾爱心物资

After installing NRM, the internal/validators js:124 throw new ERR_ INVALID_ ARG_ TYPE(name, ‘string‘, value)
随机推荐
AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0
js取整的小技巧
Is it reliable for flush to register and open an account? Is it safe?
Upgrade HDP spark to spark 2.4.8 without upgrading ambari
【学习笔记】模拟
十大券商注册开户靠谱吗?安全吗?
npm清理缓存
Two tips for block level elements
SQL analysis (query interception analysis for SQL optimization)
About using font icons in placeholder
[shangpinhui] project notes
PLSQL installation under Windows
Do you know TCP protocol (1)?
【学习笔记】差分约束
Ambari (VI) -- ambari API use
小艺人黄鑫洋受邀参加巴黎时装周儿童单元武汉站
Redis cerebral fissure
Is it reliable to open an account by digging money? Is it safe?
[JS] - [DFS, BFS application] - learning notes
ROS 笔记(08)— 服务数据的定义与使用