HDU 5400 Arithmetic Sequence (2015-year School competition 9th)

Source: Internet
Author: User

1. Title Description: Click to open the link

2. Solving ideas: The problem is solved by scanning method. According to the test instructions description, the [L,i] and [i,r] intervals constitute arithmetic progression, so that l[i],r[i] can be used to maintain the furthest length that can be extended from I to the left and right, if D1 and D2 are not equal, then the answer is l[i]*r[i] summation, otherwise r[i).

3. Code:

#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <iostream> #include <algorithm># include<cassert> #include <string> #include <sstream> #include <set> #include <bitset># include<vector> #include <stack> #include <map> #include <queue> #include <deque># include<cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <ctime># Include<cctype> #include <functional>using namespace std; #define ME (s) memset (s,0,sizeof (s)) typedef long  Long ll;typedef unsigned int uint;typedef unsigned long long ull;typedef pair <int, int> p;const int N=100000+10;int L[n],r[n];int a[n];int N,d1,d2;int Main () {while (~scanf ("%d%d%d", &n,&d1,&d2)) {for (int i=0;i&lt        ; n;i++) scanf ("%d", &a[i]); for (int i=0;i<n;i++) {if (i==0| |            A[i-1]+d1!=a[i]) l[i]=1;        else l[i]=l[i-1]+1;  } for (int i=n-1;i>=0;i--) {          if (i==n-1| |            A[I]+D2!=A[I+1]) r[i]=1;        else r[i]=r[i+1]+1;        } ll Ans=0;        if (D1!=D2) {for (int i=0;i<n;i++) ans+= (LL) l[i]*r[i];        } else {for (int i=0;i<n;i++) ans+=r[i];    } printf ("%i64d\n", ans); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5400 Arithmetic Sequence (2015-year School competition 9th)

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.