Triangles

Problem description
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 gure 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.
Input
The rst line of the input contains an integer N, the number of points given. The second line contains N integers Xi, representing the lengths of the circular arcs between two consecutive points in the circle: for 1<=i<=(N-1), Xi represents the length of the arc between between points i and i + 1; XN represents the length of the arc between points N and 1.
Output
Your program must output a single line, containing a single integer, the number of distinct equilateral triangles that can be constructed using the given points as vertices.
Sample Input
8
4 2 4 2 2 6 2 2
6
3 4 2 1 5 3
Sample Output
2
1
//题意:已知在一圆上有N个点,而这N个点的相邻点的距离已知,问从这N个点能找出多少个等边三角形。
//题解:只要找到三个点是它们的弧长相等就OK了。
//标程:
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
int sum[1000010], a[1000010];
set<int> s;
int main()
{
//    freopen("a.txt","r",stdin);
    int n, i;
    while(scanf("%d",&n)!=EOF)
    {
        s.clear();
        sum[0] = 0;
        for(i = 1; i <= n; ++ i)
        {
            scanf("%d",&a[i]);
            sum[i] = sum[i-1] + a[i];
            s.insert(sum[i]);
        }
        int temp = sum[n]/3, cnt = 0;
        for(i = 1; i <= n - 2; ++ i)
            if(s.count(sum[i])==1 && s.count(sum[i]+temp)==1 && s.count(sum[i]+2*temp)==1)
                cnt ++;
        printf("%d\n",cnt);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值