题解:
暴力枚举,然后判断是否是矩形
代码:
#include<iostream> #include<cstdio> using namespace std; int n,ans,tot,a[21],dis[21]; int read() { char ch=getchar(); int f=1,x=0; while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();} return x*f; } int main() { n=read(); for (int i=1;i<=n;i++)a[i]=read(); for (int i=1;i<=n;i++) { dis[i+1]=dis[i]+a[i]; tot+=a[i]; } for (int a=1;a<=n;a++) for (int b=a+1;b<=n;b++) for (int c=b+1;c<=n;c++) for (int d=c+1;d<=n;d++) if((dis[b]-dis[a]==dis[d]-dis[c]) &&(tot-dis[d]+dis[a]==dis[c]-dis[b]))ans++; printf("%d",ans); return 0; }