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 input contains several test cases. The rst line of a test case 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
For each test case 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.
Restrictions
3 N 10
5
1 Xi 10
3

, for 1 i N
Sample Input
8
4 2 4 2 2 6 2 2
6
3 4 2 1 5 3
Sample Output
2

1

#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
const int M= ;
int num[M] ,N ,Len ,num2[M];
int L_sum[M] ,R_sum[M] ;
int judge_Left(int id){
int Left=id;
int Right=Min(id+N-,N+N) ;
int mid ;
while(Left<=Right){
mid=(Left+Right)>> ;
if(L_sum[mid]-L_sum[id-]==Len)
return ;
else if(L_sum[mid]-L_sum[id-]>Len)
Right=mid- ;
else
Left=mid+ ;
}
return ;
}
int judge_Right(int id){
id=N+-id ;
id++ ;
int Left=id;
int Right=Min(id+N-,N+N) ;
int mid ;
while(Left<=Right){
mid=(Left+Right)>> ;
if(R_sum[mid]-R_sum[id-]==Len)
return ;
else if(R_sum[mid]-R_sum[id-]>Len)
Right=mid- ;
else
Left=mid+ ;
}
return ;
}
int main(){
int s ,ans ;
while(scanf("%d",&N)!=EOF){
s= ;
ans= ;
L_sum[]= ;
for(int i=;i<=N;i++){
scanf("%d",&num[i]) ;
num2[N-i+]=num[i] ;
s+=num[i] ;
L_sum[i]=L_sum[i-]+num[i] ;
}
if(s%){
puts("") ;
continue ;
}
Len=s/ ;
for(int i=;i<=N;i++)
L_sum[i+N]=L_sum[i+N-]+num[i] ;
R_sum[]= ;
for(int i=;i<=N;i++)
R_sum[i]=R_sum[i-]+num2[i] ;
for(int i=;i<=N;i++)
R_sum[i+N]=R_sum[i+N-]+num2[i] ;
for(int i=;i<=N;i++){
if(judge_Right(i)&&judge_Left(i))
ans++ ;
}
printf("%d\n",ans/) ;
}
return ;
}

UVA 12651 Triangles的更多相关文章

  1. uva 12508 - Triangles in the Grid(几何+计数)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/35244875 题目链接:uva 12508 ...

  2. UVA 12508 - Triangles in the Grid(计数问题)

    12508 - Triangles in the Grid 题目链接 题意:给定一个n∗m格子的矩阵,然后给定A,B.问能找到几个面积在A到B之间的三角形. 思路:枚举每一个子矩阵,然后求[0,A]的 ...

  3. UVA 12075 - Counting Triangles(容斥原理计数)

    题目链接:12075 - Counting Triangles 题意:求n * m矩形内,最多能组成几个三角形 这题和UVA 1393类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对 ...

  4. uva 11275 3D Triangles (3D-Geometry)

    uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= ...

  5. uva 11275 3D Triangles

    题意:三维空间中,给出两个三角形的左边,问是否相交. 面积法判断点在三角形内: #include<cstdio> #include<cmath> #include<cst ...

  6. UVA 12075 Counting Triangles

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  7. UVA 1393 Highways,UVA 12075 Counting Triangles —— (组合数,dp)

    先看第一题,有n*m个点,求在这些点中,有多少条直线,经过了至少两点,且不是水平的也不是竖直的. 分析:由于对称性,我们只要求一个方向的线即可.该题分成两个过程,第一个过程是求出n*m的矩形中,dp[ ...

  8. uva 11178 - Morley's Theorem

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  9. Count the number of possible triangles

    From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...

随机推荐

  1. Windows命令行查看文件的MD5

    certutil -hashfile D:\apache-tomcat-7.0.68-windows-x64.zip  MD5certutil -hashfile D:\apache-tomcat-7 ...

  2. phpcms日期时间

    PHPCMS V9调用时间标签 |日期时间格式化 转载 2016-06-17 14:58:54 标签:php PHPCMS V9 如何调用时间标签,下面分享常见的调用时间标签 |日期时间格式化 1.日 ...

  3. UCloud内核热补丁技术揭秘

  4. WPF--Calendar控件高级使用

    一.得到当前显示的月份: DateTime SelectedDay = this.MC.DisplayDate; 二.得到当前选中的天,得到当前选中的周,得到当前显示的月份: 如果你使用系统默认的事件 ...

  5. 通信原理读书笔记:常规AM调制的功率

    Proakis,通信系统原理,p101: 两个不同频率正弦和的功率为其功率的和. 计算功率时,和的平方展开后会出现两个正弦乘积项,按积化和差展开后在公共周期内积分为零.

  6. 【solr】solr5.0整合中文分词器

    1.solr自带的分词器远远满足不了中文分词的需求,经查使用最多的分词器是solr是mmseg4j分词器,具体整合大家可以参考 https://github.com/zhuomingliang/mms ...

  7. Python 模块学习:re模块

    今天学习了Python中有关正则表达式的知识.关于正则表达式的语法,不作过多解释,网上有许多学习的资料.这里主要介绍Python中常用的正则表达式处理函数. 方法/属性 作用 match() 决定 R ...

  8. 删除指定的文件.bat

    @echo offattrib -s -h -r /s /d C:\*Thumbs.dbattrib -s -h -r /s /d D:\*Thumbs.dbattrib -s -h -r /s /d ...

  9. solr基于tomcat增加主界面登录权限

    tomcat-user.xml增加下面标签(用户名,密码,角色)<user username="admin" password="new-password" ...

  10. 51nod 1120 机器人走方格 V3 卡特兰数 lucas定理

    N * N的方格,从左上到右下画一条线.一个机器人从左上走到右下,只能向右或向下走.并要求只能在这条线的上面或下面走,不能穿越这条线,有多少种不同的走法?由于方法数量可能很大,只需要输出Mod 100 ...