Day3-T1
Describe:暴力出奇迹 [ 注意步长0.5!]
code:
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int f=1,res=0,ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();};
while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();};
return res*f;
}
int n,l,sum,a[201];
double b[201],b2[201];
int tot1,tot2,ans;
int main()
{
n=read(),l=read();
for(int i=1;i<=n;i++)a[i]=read();
sort(a+1,a+n+1);
for(double i=0.5;i<l;i+=0.5) //可行性剪枝:仅可能存在于某节点或相邻两节点中点
{
tot1=0;tot2=0;sum=0;
memset(b,0,sizeof(b));
memset(b2,0,sizeof(b2));
for(int j=1;j<=n;j++) //L or R
if(a[j]<i)b[++tot1]=i-a[j];
else if(a[j]>i)b2[++tot2]=a[j]-i;
sort(b+1,b+tot1+1);sort(b2+1,b2+tot2+1);
for(int i=1;i<=min(tot1,tot2);i++)
if(b[i]==b2[i])sum++;else break;
if(sum==tot1||sum==tot2)ans++; //与左半部分一样多或与右半部分一样多
}
cout<<ans<<endl;
}

浙公网安备 33010602011771号