当前位置:网站首页>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;
}
}
边栏推荐
- The micro kernel zephyr is supported by many manufacturers!
- Prometheus monitoring (I)
- Is it reliable to open an account by digging money? Is it safe?
- AI首席架构师8-AICA-高翔 《深入理解和实践飞桨2.0》
- 设置cmd的编码为utf-8
- Generation and verification of JWT token
- SQL analysis (query interception analysis for SQL optimization)
- 抗洪救灾,共克时艰,城联优品捐赠10万元爱心物资驰援英德
- 11grac turn off archive log
- Activity隐式跳转
猜你喜欢
Software testing and quality final review
Do you know TCP protocol (2)?
Chenglian premium products donated love materials for flood fighting and disaster relief to Yingde
B_ QuRT_ User_ Guide(28)
Devops foundation chapter Jenkins deployment (II)
Ambari (V) ---ambari integrated Azkaban (valid for personal test)
Image translation /transformer:ittr: unpaired image to image translation with transformers
Prometheus + grafana + MySQL master-slave replication + host monitoring
Ambari (VIII) --- ambari integrated impala document (valid for personal test)
SQL master-slave replication setup
随机推荐
【学习笔记】拟阵
Redis cerebral fissure
sql分析(查询截取分析做sql优化)
2022巴黎时装周儿童单元6.19武汉站圆满落幕
图像翻译:UVCGAN: UNET VISION TRANSFORMER CYCLE-CONSISTENT GAN FOR UNPAIRED IMAGE-TO-IMAGE TRANSLATION
B_ QuRT_ User_ Guide(29)
Preparation for Oracle 11g RAC deployment on centos7
Discussion on the application of GIS 3D system in mining industry
Unity - use of API related to Pico development input system ---c
Study notes 22/1/17
解决npm ERR! Unexpected end of JSON input while parsing near问题
MySQL single table access method
ROS notes (09) - query and setting of parameters
Redis cluster deployment and application scenarios
Airflow2 configuration windows azure SSO details based on oauth2 protocol
Redis master-slave structure and application scenarios
抗洪救灾,共克时艰,城联优品捐赠10万元爱心物资驰援英德
Modifying the SSH default port when installing Oracle RAC makes CRS unable to install
MySQL row format parsing
图像翻译/Transformer:ITTR: Unpaired Image-to-Image Translation with Transformers用Transfor进行非配对图像对图像的转换