思路
绳子长度扩大一倍,直接枚举
C++ 代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 20010;
int res;
int s[N];
int main()
{
int n,L;
cin >> n >> L;
L*=2; //折叠点可能小数,两倍扩大避免小数
for (int i = 0; i < n; i ++ )
{
int x;
cin >> x;
s[x*2]=1;//两倍扩大
}
for(int i=1;i<L;i++)
{
int j=i,k=i;
while(j>=0&&k<=L)
{
j--,k++;
if(s[j]!=s[k])break;
}
if(j==-1||k==L+1) res++;
}
cout << res;
}