This problem is actually examined from which can find a few diameters, because this time the data range is small, so just set a two-dimensional array, record each point and each point from the zero-based position, and finally set a variable record perimeter, and finally use a loop to search the location is less than half the circumference of the data, Plus half of the perimeter, if there are any in the array, there is a total of k* (k-1)/2 rectangles if there are k.
The code is as follows (the code is slightly more cumbersome than the above method, but the basic idea is the same):
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>using namespacestd;inti_number,i_temp;inti_place[100000];intI_total=0, i_side=0; intMain () {CIN>>I_number; i_place[0]=1; for(intI=0; i<i_number;i++) {cin>>i_temp; I_total=i_total+i_temp; I_place[i_total]=1; } for(intI=0; i<i_total/2; i++) { if(i_place[i]==1) { if(i_place[i_total/2+i]==1) {I_side=i_side+1; } }} cout<<i_side* (i_side-1)/2<<Endl; return 0;}
Thank you for watching my blog, if there is not enough to point out, thank you.
Bzoj 1800 fly-Flying Chess