The way of Garlic 2015 Program Design Competition Preliminary round fourth--Iqiyi art's Homemade Program

Source: Internet
Author: User
Tags iqiyi

The way of Garlic 2015 Program Design Competition Preliminary round fourth--Iqiyi art's Homemade Program

(i) the question surface

Iqiyi as a video website giant, to hundreds of millions of users every day to provide "enjoy quality" service. In addition to the introduction of some excellent film and television works, Iqiyi also made some such as the wonderful said, Xiao Sonchi talk about the home-made programs. Iqiyi recently prepared to make four new programs, namely W, X, Y, Z; but there are only two studios that can be used to record these programs, namely Studio A and Studio B.

The site of the W program is relatively complex, each period to be recorded in Studio A, X program camera position adjustment will affect the quality of the program, each period is fixed in studio B to record. The program Y and program Z construction are relatively easy to move, photography is not a special requirement, can be recorded in Studio A, can also be recorded in Studio B.

Known W program altogether Ew period, each period recording need W minute, x program altogether ex period, each period recording need X minutes; Y program Total Ey period, each period recording need y minutes; Z program Total Ez period, each period recording need Z minutes.

Each episode must be recorded in the same studio from start to finish, and the entire program does not have to be recorded in the same studio for each period. Now Iqiyi hope in the shortest possible time in the two studios will record four programs, in the program are continuously recorded under the assumption that you can help them figure out the program to complete the minimum time required for recording?

Input format

The first line enters an integer T (1≤t≤50) that represents the number of data groups.

Next, enter the T line data, enter a set of 8 integers per line Ew, ex, EY, EZ, W, X, Y, Z (1≤ew, ex, EY, EZ, W, x, Y, z≤106).

Output format

Output T lines, one integer per line, indicating the minimum time required for this group of four programs to be recorded in a continuous recording.

Example 1

Input:

1100 1 3 5 10 1 10 10

Output:

1000

(ii) Reference source

1 ImportJava.util.Scanner;2 3  Public classMain {4     Private Static FinalScanner READER =NewScanner (system.in);5     Private Static FinalString Line_separator =System6. GetProperty ("Line.separator");7 8      Public Static voidMain (string[] args) {9         intT =reader.nextint ();Ten         //start reading the next line One reader.nextline (); AStringBuilder Builder =NewStringBuilder (); -          while(t--> 0) { -String[] line = Reader.nextline (). Split (""); the             intE_w = Integer.parseint (line[0]); -             inte_x = Integer.parseint (line[1]); -             inte_y = Integer.parseint (line[2]); -             intE_z = Integer.parseint (line[3]); +             intW = Integer.parseint (line[4]); -             intX = Integer.parseint (line[5]); +             intY = Integer.parseint (line[6]); A             intZ = Integer.parseint (line[7]); at  -             //Higher efficiency on top -             //int e_w = Reader.nextint (); -             //int e_x = Reader.nextint (); -             //int e_y = Reader.nextint (); -             //int e_z = Reader.nextint (); in             //int W = Reader.nextint (); -             //int X = Reader.nextint (); to             //int Y = Reader.nextint (); +             //int Z = Reader.nextint (); -  the             /* * * Assuming program Y in studio a recorded T period, program Z in Studio B recording S period when in Studio A: A=y*t+z*s+e_w*w $ * When in Studio B: b=y* (e_y-t) +z* (e_z-s) +e_x*xPanax Notoginseng * Target is | a-b| min, | a-b|=| e_w*w-e_x*x-e_y*y-e_z*z+2*y*t+2*z*s| -              */ the             //e=e_w*w-e_x*x-e_y*y-e_z*z +             LongE = (Long) E_w * W-(Long) e_x * x-(Long) e_y *Y A- (Long) E_z *Z; the  +             //lower limit of T -             intT_low =Math.min ( $ Math.max ( $(int) Math.floor (Double) (-e-(Long) E_z -* (Z << 1)) -/(Y << 1)), 0), e_y); the             //Lower limit of s -             intS_low =Math.min (Wuyi Math.max ( the(int) Math.floor (Double) (-e-(Long) e_y -* (Y << 1)) Wu/(Z << 1)), 0), e_z); -             //Upper limit of T About             intT_upper =Math.min ( $Math.max ((int) Math.ceil (Double)-E/(Y << 1)), 0), e_y); -             //the upper limit of s -             intS_upper =Math.min ( -Math.max ((int) Math.ceil (Double)-E/(Z << 1)), 0), e_z); A             intT0 = 0; +             intS0 = 0; the             // | Minimum value of a-b| -             LongA_b_min =-1; $             //traverse all the values of T, s take make | a-b| the integer nearest 0 the              for(intt = t_upper; T >= T_low; t--) { the                 Doublej = (Double) (-e-(Long) T * (Y << 1))/(Z << 1); the                 ints = math.min (Math.max (int) Math.Round (j), S_low), s_upper); the                 LongA_b = Math.Abs (E + (Long) T * (Y << 1) + (Long) s -* (Z << 1)); in                 if(A_b < A_b_min | | A_b_min < 0) { theA_b_min =A_b; theT0 =T; AboutS0 =s; the                 } the             } the  +             LongE_min = Math.max ((Long) Y * t0 + (Long) Z * S0 + (Long) E_w -* W, (Long) Y * (e_y-t0) + (Long) Z * (E_z-S0) the+ (Long) e_x *X);Bayi builder.append (e_min). Append (line_separator); the         } the System.out.println (builder.tostring ()); -     } -}
Java

The way of Garlic 2015 Program Design Competition Preliminary round fourth--Iqiyi art's homemade program

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.