(数学) bzoj 1800

1800: [Ahoi2009]fly 飞行棋

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 973  Solved: 808
[Submit][Status][Discuss]

Description

给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依圆周顺序排列。 请找出这些点中有没有可以围成矩形的,并希望在最短时间内找出所有不重复矩形。

Input

第一行为正整数N,表示点的个数,接下来N行分别为这N个点所分割的各个圆弧长度

Output

所构成不重复矩形的个数

Sample Input

8
1
2
2
3
1
1
3
3


Sample Output

3

HINT

N<= 20

 
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int tot,n,dist[25],ans;
int main()
{
    int x;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        dist[i]=dist[i-1]+x;
        tot+=x;
    }
    for(int a=1;a<=n;a++)
    {
        for(int b=a+1;b<=n;b++)
        {
            for(int c=b+1;c<=n;c++)
            {
                for(int d=c+1;d<=n;d++)
                {
                    if(dist[b]-dist[a]==dist[d]-dist[c]&&tot-dist[d]+dist[a]==dist[c]-dist[b])
                        ans++;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

  

posted @ 2015-05-23 09:55  waterfull  阅读(156)  评论(0编辑  收藏  举报