1800: [Ahoi2009]fly 飞行棋
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1332 Solved: 1084
[ Submit][ Status][ Discuss]
Description
给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依圆周顺序排列。 请找出这些点中有没有可以围成矩形的,并希望在最短时间内找出所有不重复矩形。
Input
第一行为正整数N,表示点的个数,接下来N行分别为这N个点所分割的各个圆弧长度
Output
所构成不重复矩形的个数
Sample Input
8
1
2
2
3
1
1
3
3
1
2
2
3
1
1
3
3
Sample Output
3
HINT
N<= 20
Source
矩形 = 三个直角的四边形
直角 = 半圆弧对应的圆周角
果然枚举是最开心的
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<bitset>
using namespace std;
const int maxn = 25;
int n,ans,tot,a[maxn],now[10];
bool check(int x)
{
int po = 1,sum = 0;
for (; x; x >>= 1) {
if (x&1) now[++sum] = po;
++po;
}
return sum == 4;
}
int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d",&a[i]),tot += a[i];
for (int i = 0; i < (1<<n); i++)
if (check(i)) {
int sum = 0;
for (int j = now[1]; j < now[3]; j++) sum += a[j];
if (sum * 2 != tot) continue;
sum = 0;
for (int j = now[2]; j < now[4]; j++) sum += a[j];
if (sum * 2 != tot) continue;
sum = 0;
for (int j = now[3]; j <= n; j++) sum += a[j];
for (int j = 1; j < now[1]; j++) sum += a[j];
if (sum * 2 != tot) continue;
++ans;
}
cout << ans;
return 0;
}