Bilibili, Acfun ... and more! "Recursive algorithm"

Source: Internet
Author: User

Source: HTTP://ACM.UESTC.EDU.CN/#/PROBLEM/SHOW/3

Exercises

Test instructions: Play a video file, there are playback speed and buffering speed two, because the author's hobby, before playing to buffer for a few seconds (this period of time is not calculated in the total time), if the playback file size is equal to the buffer file size, the buffer file is not finished buffering, the player will start from scratch, but the buffer continues to buffer.

Summarize several key points:

1. When a replay is required, the size of the buffer (where the property is equal to the size of the buffer before the start of the playback), the situation is similar to the beginning of the case, but the buffer size is not the same as before.

2. When the playback size equals the buffer size (one of the equations is listed here), determine if the buffer size is greater than or equal to the total size, or replay.

According to the information of key points, can sniff out the taste of recursive algorithm, what is recursive algorithm?

In mathematics, recursion is X0 a set, f (X0) = f (f (X1)), and X0 equals the dependent variable in X1. the outer layer requires the result of an inner operation

In programming, recursion is the function itself calling itself, but there is a recursive exit. function calls are actually made in "stacks", and the function that is called first is at the bottom of the stack.

Online buckle A picture can be very image understanding recursion (if there is infringement immediately deleted)

Back to the point:

Set the playback speed to x, the buffer speed to Y, the time to play ahead of T, the total size of the file Z, the time required T, re-play the buffer size before the moment.

1. There are two kinds of situations.

1) The network speed times the rod, once did not replay

t = z/x

Condition: Buffer speed y is greater than or equal to playback speed x or when you want to replay, the buffer size is greater than the total size

Y >= X | | T/(x-y) >= s/x

2) maddening situation, always re-play

t = t1 + t2 + t3 ... + tn;

TN = size/(x-y);//nth Recursive playback time

Recursive same formula: Buffer file size sizes, when calling its own function, the buffer file size becomes size/(x-y) *x;

recursive termination Condition: Buffer file size greater than or equal to total file size S:size/(x-y) *x >= S

Attached code:

C code#include<stdio.h> #define M 1000double time (double size, int X, int Y, int S);//recursive function int main () {int num,x[m],y [m],s[m],t[m];//x playspeed playback speed, Y bufferspeed buffer speed, S totalsize file total size int i;//loop parameter scanf ("%d", &num);//test number for (i = 0; i < num; i++) {scanf ("%d%d%d", &x[i], &y[i],&t[i], &s[i]);} for (i = 0; i < num; i++) {if (X[i] <= Y[i] | | T[i]/(Double) (X[i]-y[i]) >= S[i]/(double) x[i])//Network Good {printf ("Case #%d:%.3f\n", i+1, S[i]/(double) x[i]);} else//Spicy Chicken Speed {printf ("Case #%d:%.3f\n", i + 1, time (t[i] * y[i], x[i], y[i], s[i]));}}    return 0;}  Double time (double size,int x,int y,int s)//size is a buffer file size that is re-played before the moment, as a recursive variable {double t = 0;if (Size/(x-y) *x < S)//recursive termination condition {T = Size/(x-y) + Time (Size/(x-y) *x, X, Y, S);} Else{t = S/(double) X;} return t;}

  

Have any questions welcome in the message area to communicate!

Bilibili, Acfun ... and more! "Recursive algorithm"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.