HDU 5328 problem Killer (water problem)

Source: Internet
Author: User

Test instructions: For a sequence, to find a continuous sub-sequence of linear or equal ratio , to seek its longest length.

Idea: Sweep two times, judge the linear or equal. Swipe from left to right, maintain a sliding window, consider the newly added number, if the requirements are met, update the length, otherwise only the last two digits, the other deleted, and then continue to consider the next number. The same is true, just pay attention to the problem of precision.

Someone else's code:

1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAX = 1e6+2;4 intArr[max];5 6 intMainvoid)7 {8     //freopen ("In.txt", "R", stdin);9     intt =0;Tenscanf"%d", &t); One      while(t--) A     { -         intn =0; -scanf"%d", &n); the  -          for(intI=1; i<=n; ++i) -         { -scanf"%d", &arr[i]); +         } -  +         if(n==1|| n==2) A         { atprintf"%d\n", n); -             Continue; -         } -  -         intL, R; -L =1; in         intdiff = arr[2]-arr[1]; -         intANS1 =2; to          for(r=3; r<=n; ++R) +         { -             if(Arr[r]-arr[r-1] !=diff) the             { *diff = arr[r]-arr[r-1]; $L = r1;Panax Notoginseng             } -ANS1 = Max (ans1, r-l+1); the         } +  AL=1; the         DoubleDdiff =1.0*arr[2]/arr[1]; +         intAns2 =2; -          for(r=3; r<=n; ++R) $         { $             if(Fabs (1.0*arr[r]/arr[r-1]-Ddiff) >0.000001) -             { -Ddiff =1.0*arr[r]/arr[r-1]; theL = r1; -             }WuyiANS2 = Max (Ans2, r-l+1); the         } -printf"%d\n", Max (ans1, Ans2)); Wu     } -     return 0; About}
AC Code

HDU 5328 problem Killer (water problem)

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.