【bzoj1800】[Ahoi2009]fly 飞行棋

1800: [Ahoi2009]fly 飞行棋

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

[ Submit][ Status][ Discuss]


暴力

代码:
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;

typedef long long LL;

const int INF = 2147483647;
const int maxn = 30;
const int maxs = 10000;
const LL seed = 163;
const LL hyj = 1e9 + 7;

LL ha[maxs];
int tots,s[maxs][10];
int n,ans,a[maxn],sum[maxn];
int mark[maxn];

inline LL getint()
{
	LL ret = 0,f = 1;
	char c = getchar();
	while (c < '0' || c > '9')
	{
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9')
		ret = ret * 10 + c - '0',c = getchar();
	return ret * f;
}

inline void judge()
{
	int j = 1,cur = 1;
	memset(sum,0,sizeof(sum));
	for (int i = 1; i <= n; i++)
	{
		if (mark[i]) cur++;
		else sum[cur] += a[j++];
	}
	sum[1] += sum[5]; sum[5] = 0;
	if (sum[1] == sum[3] && sum[2] == sum[4] && sum[1] && sum[2]) 
	{
		tots++; 
		cur = 0; j = 0;
		for (int i = 1; i <= n; i++) 
		{
			if (!mark[i]) j++;
			else s[tots][++cur] = j;
		}
		if (s[tots][cur] == n - 4) s[tots][cur] = 0;
		sort(s[tots] + 1,s[tots] + 5);
	}
}

inline void dfs(int x,int cnt)
{
	if (cnt == 4) {judge(); return;}
	if (x > n) return;
	for (int i = x; i <= n; i++)
	{
		mark[i] = 1;
		dfs(i + 1,cnt + 1);
		mark[i] = 0;
	}
}

int main()
{
	#ifdef dyf
		freopen("hyj1.txt","r",stdin);
	#endif
	n = getint();
	for (int i = 1; i <= n; i++) a[i] = getint();
	n += 4; dfs(1,0);
	for (int i = 1; i <= tots; i++)
		for (int j = 1; j <= 4; j++)
			ha[i] = (ha[i] * seed + s[i][j]) % hyj;
	sort(ha + 1,ha + tots + 1);
	for (int i = 1; i <= tots; i++)
		if (ha[i] != ha[i - 1])
			ans++;
	printf("%d",ans);
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值