1583: [Usaco2009 mar]moon mooing Moo Moo

Source: Internet
Author: User

1583: [Usaco2009 mar]moon mooing Moo Moo time limit:10 Sec Memory limit:64 MB
submit:244 solved:126
[Submit] [Status] [Discuss] Description

Input

First row two numbers, C and N

Second row 3 numbers, a1,b1,c1 the third row 3 numbers, A2,B2,C2

Output

An integer that represents the longest howl.

Sample Input3 10
4 3 3
17 8 2
Sample Output65
HINT Source

Gold

Puzzle: It is hard to imagine Usaco unexpectedly have this water problem, not to mention still gold division ... (PS: But I will tell you that I am not only the first reaction is to use the heap to do, but also to tease once--forget to open Int64 TT)

In fact, because the topic said \ (a_1 \leq d_1 \) and \ (a_2 \leq d_2 \), so \ (\frac{a_1}{d_1} \geq 1 \) and \ (\frac{a_2}{d_2} \geq 1 \), so the entire iteration in a rising Stage, that is, the problem is completely a sort of merger and order of things-direct two lines of linear merging, time complexity \ (O\left (N \right) \)

1/**************************************************************2Problem:15833 User:hansbug4 language:pascal5 result:accepted6Time:1304Ms7Memory:39288KB8****************************************************************/9  Ten var One I,j,k,l,m,n,a1,b1,c1,a2,b2,c2,i1,i2:longint; A X1,x2:int64; -A:Array[0..5000000] ofInt64; - begin the readln (m,n); - readln (A1,B1,C1); - readln (A2,B2,C2); -a[1]:=m;i:=2; +i1:=1; i2:=1; -x1:= (A1*M)Divc1+B1; +x2:= (A2*M)Divc2+B2; A       whileI<=n Do at            begin -                 ifX1<x2 Then -                    begin -                         ifx1<>a[i-1] Then -                            begin -a[i]:=X1; in Inc (i); -                            End; to Inc (I1); +x1:= (A[I1]*A1)Divc1+B1; -                    End the                 Else *                     begin $                          ifx2<>a[i-1] ThenPanax Notoginseng                             begin -a[i]:=x2; the Inc (i); +                             End; A Inc (I2); thex2:= (A[I2]*A2)Divc2+B2; +                     End; -            End; $ Writeln (A[n]); $ Readln; - End.

1583: [Usaco2009 mar]moon mooing Moo Moo

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.