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;
}

相关文章

显卡天梯图2024最新版,显卡是电脑进行图形处理的重要设备,...
初始化电脑时出现问题怎么办,可以使用win系统的安装介质,连...
todesk远程开机怎么设置,两台电脑要在同一局域网内,然后需...
油猴谷歌插件怎么安装,可以通过谷歌应用商店进行安装,需要...
虚拟内存这个名词想必很多人都听说过,我们在使用电脑的时候...
win11本地账户怎么改名?win11很多操作都变了样,用户如果想要...