题目
给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依圆周顺序排列。 请找出这些点中有没有可以围成矩形的,并希望在最短时间内找出所有不重复矩形。
输入格式
第一行为正整数N,表示点的个数,接下来N行分别为这N个点所分割的各个圆弧长度
输出格式
所构成不重复矩形的个数
输入样例
8
1
2
2
3
1
1
3
3
输出样例
3
解释
N<= 20
题解
四个点abcd能构成矩形,当且仅当
顺序枚举判断一下就好了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u]; k != -1; k = ed[k].nxt)
using namespace std;
const int maxn = 25,maxm = 100005,INF = 1000000000;
inline int RD(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57) {out = (out << 1) + (out << 3) + c - '0'; c = getchar();}
return out * flag;
}
int d[maxn][maxn],n,A[maxn],tot = 0,ans = 0;
int main(){
n = RD();
REP(i,n) tot += (A[i] = RD());
REP(i,n) A[i] += A[i - 1];
REP(i,n) for (int j = i + 1; j <= n; j++)
d[i][j] = A[j - 1] - A[i - 1];
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 (d[i][j] == d[k][l] && d[j][k] == (tot - d[i][l]))
ans++;
printf("%d
",ans);
return 0;
}