UVa 1594 (Floyd ring) Ducci Sequence

Source: Internet
Author: User

The problem of P42 that calculator in Great White Book is used this method, Floyd the Circle law.

Of course, using the map in STL is also possible.

1#include <cstdio>2#include <cmath>3 4 Const intMAXN = -;5 intN;6 intA[MAXN], B[MAXN], C[MAXN];7 8 voidNextinta[])9 {Ten      for(inti =0; I < n-1; i++) A[i] = Std::abs (A[i]-a[i +1]); OneA[n-1] = a[0]; A } -  - BOOLEqualintA[],intb[]) the { -      for(inti =0; I < n; i++)if(A[i]! = B[i])return false; -     return true; - } +  - intMain () + { A     //freopen ("In.txt", "R", stdin); at  -     intT scanf"%d", &T); -      while(t--) -     { -scanf"%d", &n); -          for(inti =0; I < n; i++) {scanf ("%d", &a[i]); B[i] =a[i];} inA[n] = b[n] = a[0]; -n++; to  +         BOOLloop =true; -          for(inti =0; I <1010; i++) the         { * Next (a); next ( b); next (b) ; $             if(Equal (A, C)) {loop =false; Break; }Panax Notoginseng             if(Equal (b, C)) {loop =false; Break; } -             if(Equal (A, B)) {loop =true; Break; } the         } +printf"%s\n", loop?"LOOP":"ZERO"); A     } the  +     return 0; -}
code June

UVa 1594 (Floyd ring) Ducci Sequence

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.