BZOJ 1800: [Ahoi2009]fly 飞行棋( 枚举 )

O(N2)算出有x条直径然后答案就是x(x-1)/2...这个数据范围是闹哪样! 

------------------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;
 
const int maxn = 29;
 
int N, w[maxn];
 
int main() {
scanf("%d", &N);
w[0] = 0;
for(int i = 1; i <= N; i++) {
scanf("%d", w + i);
w[i] += w[i - 1];
}
if(w[N] & 1) {
puts("0"); return 0;
}
int ans = 0;
for(int i = 1; i <= N; i++)
for(int j = i + 1; j <= N; j++)
if(w[j] - w[i] == (w[N] >> 1)) ans++;
printf("%d ", ans * (ans - 1) >> 1);
return 0;
}

------------------------------------------------------------------------------------------

1800: [Ahoi2009]fly 飞行棋

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1089  Solved: 902
[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

Source

原文地址:https://www.cnblogs.com/JSZX11556/p/4931878.html