Bzoj 1800: [Ahoi2009]fly Flying Chess "Violence"

Source: Internet
Author: User

Description

Given a number of points on the circumference, the arc length between the point and the point is known, and the values are positive integers, arranged in a circular order. Please find out if there are any rectangles in these points and hope to find all the non-repeating rectangles in the shortest time.

Input

The first action is an integer n, which represents the number of points, and the next n rows are the individual arc lengths divided by the N points.

Output

The number of non-repeating rectangles that are formed

Sample Input

8
1
2
2
3
1
1
3
3


Sample Output

3

HINT

n<= 20

Idea: Well n<=20 tease me tut

#include <cstdio>

#include <string.h>

#include <iostream>

#include <algorithm>

#define MAXN 400009

#define LL Long Long

using namespace Std;

int SUM[MAXN],A[MAXN];

int main ()

{

int n,ans=0;

scanf ("%d", &n);

for (int i=1;i<=n;i++)

{

scanf ("%d", &a[i]);

Sum[i]+=sum[i-1]+a[i];

}

for (int i=1;i<=n;i++)

{

for (int j=i+1;j<=n;j++)

{

for (int k=j+1;k<=n;k++)

{

for (int l=k+1;l<=n;l++)

{

if (sum[l]-sum[j]== (sum[n]>>1) && Sum[l]-sum[k]==sum[j]-sum[i])

{

ans++;

}

}

}

}

}

printf ("%d\n", ans);

return 0;

}

Bzoj 1800: [Ahoi2009]fly Flight Chess "violence"

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.