spoj ADAFENCE - Ada and Fence(水题)

这篇博客介绍了如何帮助Ada用有限的柱子建造不同形状的k边形围栏。输入包含测试用例数量、柱子位置数和围栏边数,以及每个柱子间弧长。输出是可行的不同k边形围栏的数量。题目强调了不同围栏的定义并给出了示例输入输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ADAFENCE - Ada and Fence

#datastructures #pointers

 

Ada the Ladybug owns a circular land. She wants to enclose it with fence. Anyway since nobody sells round planks, she has decided to fence it to shape of regular k-gon. Problem is, that there is only limited number or places (on circle) where pilars can be built. Ada has asked you, to find out the number of different regular k-gon shaped fences which can be built on her land (two k-gon's are considered different if they share NO common pillar).

Input

The first line will contain T, the number of test-cases.

Then T test-cases follow, each beginning with two integers 3 ≤ K ≤ N ≤ 1053 ≤ K ≤ 100, the number of places where pillar can be built and number of edges of regular k-gon

Afterward a line with N integers 1 ≤ Di ≤ 100 follow, meaning the length of arc between two consecutive points where pillar can be built. The sum of all lengths will be divisible by K.

Sum of over all test-cases won't exceed 2*106

Output

For each test-case print the number of different regular k-gon shaped fences which can be built.

Example Input

3
5 3
1 2 3 2 1
15 4
1 2 2 2 1 2 2 1 1 2 1 2 1 2 2
10 5
1 1 1 1 1 1 1 1 1 1

Example Output

1
1
2
#include<bits/stdc++.h>
#define MAXN 100005
#define MAXM 10000005 
using namespace std;
int d[MAXN],q[MAXM];
int main()
{
	int cas;
	scanf("%d",&cas);
	while(cas--)
	{
		int n,k;
		scanf("%d%d",&n,&k);
		int sum=0;
		memset(q,0,sizeof(q));
		q[0]=1;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&d[i]);
			sum+=d[i];
			q[sum]=1;
		}
		int l=sum/k;
		int ans=0;int cnt=0;
		for(int i=0;i<l;i+=d[cnt++])
		{
			int flag=1;
			for(int j=0;j<k;j++)
			{
				if(!q[j*l+i])
				{
					flag=0;
					break;
				}
			}
			if(flag)
				ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值