Moon Dancers

题目描述

The moon dancers, as their name suggests, is a group of people who dances to pray the moon. The moon is a goddess for their tribe, they dance every full moon to get the moon blessings and guarantee the tribe another moon cycle of wellness.

Some researchers are very interested in the peculiar dance these moon dancers perform on the full moon. It is marvelous to see how they dance around a circle, each dancer positioned and performing an exact set of moves that have been passed between dancers for generations. At some point of the dance, each of the N dancers sit at some point in the perimeter of the circle, no two dancers sit in the same place, and they start singing the song of times. Then, suddenly, a set of K dancers stand up and dance rotating counter clockwise around the circle until each of the K dancers meet with a dancer that is sitting, making K pairs of dancers, all of the K dancers will have rotated the same amount of degrees around the circle. At this point the K pairs continue with the dance while the N−2∗K (possibly none) dancers that are not matched continue singing the song of times.

Knowing your programming skills, researchers have come to you and ask for help on a very specific task: given the position of each of the N dancers when they sit at the perimeter of the circle, can you find the maximum number of pairs that can be matched to continue the dance?

输入

The first line contains a single integer N (2≤N≤360), representing the number of dancers in the tribe. The second and last line contains N integer numbers separated by a space, representing the angle in degrees ai (0≤ai<360) where the i-th dancer sits, it is guaranteed no two dancers will sit in the same place.

输出

Output a line containing a single integer. The maximum number of pairs that can be matched to continue the dance.

代码

#include <iostream>
#include <map>
#include<cstring>
using namespace std;
const int N=4000;
typedef pair<int,int>PII;
map<int,int>m;
int  p[N];
int rec=0;
bool s[N],st[N],sk[N];
int ma=0;
bool find(int t,int y)
{
    sk[t]=1;
    int x=(t-y+360)%360;
    if(!s[x]||sk[x])return 0;
    if(!st[x]||find(x,y))
    {
        st[x]=1;
        st[t]=1;
        return 1;
    }
    return 0;
}
int main ()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>p[i],s[p[i]]=1;
    for(int i=1;i<360;i++)
    {
        int sum=0;
        m.clear();
        memset(st,0,sizeof st);
        for(int j=1;j<=n;j++)
        {
            if(!st[p[j]])
            {
                memset(sk,0,sizeof sk);
                int t=(p[j]+i)%360;
                if(s[t]&&!st[t])
                {
                    sum++;
                    st[t]=1;
                    st[p[j]]=1;
                }
                else if(find(p[j],i))sum++;
            }
        }
        rec=max(rec,sum);
    }
    cout<<rec<<endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值