Problem F Triangles

You will be given N points on a circle. You must write a program to determine how many distinct
equilateral triangles can be constructed using the given points as vertices.
The figure below illustrates an example: (a) shows a set of points, determined by the lengths of
the circular arcs that have adjacent points as extremes; and (b) shows the two triangles which can be
built with these points.
题目大意:
一个圆上有n个点,则给出其中有n隔间的长度,求组成等边三角形的方案数
思路:1到n个点遍历,从当前点到三分之一弧度长的地方应该有一个点,否则构不成等边三角形,有则下一个三分之一弧度长的地方应该有一个点,若有则方案数加一,最后输出ans/3(每一个方案遍历了三次);
重点是求出每一个点之后长度表示,前缀和与lower_bound来求区间长度降低复杂度。
附ac代码:

#include
#include
#include
using namespace std;
int a[200005],pre[200005];
int main() {
	int n,sum=0,ev,ans=0,k=0,count;
	cin>>n;
	for(int i=0; i>a[i];
		sum+=a[i];
		a[i+n]=a[i];
	}
	pre[0]=a[0];
	for(int i=1; i<2*n; i++) {
		pre[i]=pre[i-1]+a[i];
	}
	ev=sum/3;
	if(ev*3!=sum) {
		cout<<0;
		return 0;
	}

	for(int i=0; i=i+n) {
			continue;
		}
		count=pre[k]+ev;
		k=lower_bound(pre,pre+2*n,count)-pre;
		if(k>=i+n) {
			continue;
		}
		count=pre[k]+ev;
		k=lower_bound(pre,pre+2*n,count)-pre;
		if(k>=i+n) {
			continue;
		}
		ans++;
	}
	cout<

你可能感兴趣的:(Problem F Triangles)