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

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <queue>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <vector>
  7. #include <queue>
  8. #include <set>
  9. #include <algorithm>
  10. #include <map>
  11. #include <stack>
  12. #include <math.h>
  13. #define Max(a,b) ((a)>(b)?(a):(b))
  14. #define Min(a,b) ((a)<(b)?(a):(b))
  15. using namespace std ;
  16. typedef long long LL ;
  17. const int M= ;
  18. int num[M] ,N ,Len ,num2[M];
  19. int L_sum[M] ,R_sum[M] ;
  20. int judge_Left(int id){
  21. int Left=id;
  22. int Right=Min(id+N-,N+N) ;
  23. int mid ;
  24. while(Left<=Right){
  25. mid=(Left+Right)>> ;
  26. if(L_sum[mid]-L_sum[id-]==Len)
  27. return ;
  28. else if(L_sum[mid]-L_sum[id-]>Len)
  29. Right=mid- ;
  30. else
  31. Left=mid+ ;
  32. }
  33. return ;
  34. }
  35. int judge_Right(int id){
  36. id=N+-id ;
  37. id++ ;
  38. int Left=id;
  39. int Right=Min(id+N-,N+N) ;
  40. int mid ;
  41. while(Left<=Right){
  42. mid=(Left+Right)>> ;
  43. if(R_sum[mid]-R_sum[id-]==Len)
  44. return ;
  45. else if(R_sum[mid]-R_sum[id-]>Len)
  46. Right=mid- ;
  47. else
  48. Left=mid+ ;
  49. }
  50. return ;
  51. }
  52. int main(){
  53. int s ,ans ;
  54. while(scanf("%d",&N)!=EOF){
  55. s= ;
  56. ans= ;
  57. L_sum[]= ;
  58. for(int i=;i<=N;i++){
  59. scanf("%d",&num[i]) ;
  60. num2[N-i+]=num[i] ;
  61. s+=num[i] ;
  62. L_sum[i]=L_sum[i-]+num[i] ;
  63. }
  64. if(s%){
  65. puts("") ;
  66. continue ;
  67. }
  68. Len=s/ ;
  69. for(int i=;i<=N;i++)
  70. L_sum[i+N]=L_sum[i+N-]+num[i] ;
  71. R_sum[]= ;
  72. for(int i=;i<=N;i++)
  73. R_sum[i]=R_sum[i-]+num2[i] ;
  74. for(int i=;i<=N;i++)
  75. R_sum[i+N]=R_sum[i+N-]+num2[i] ;
  76. for(int i=;i<=N;i++){
  77. if(judge_Right(i)&&judge_Left(i))
  78. ans++ ;
  79. }
  80. printf("%d\n",ans/) ;
  81. }
  82. return ;
  83. }

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. thymeleaf之fragment

    MUEAS项目,web前端采用thymeleaf作为展示层.这个view解析器,个人觉得非常不错.简单而且性能也比较好!个人觉得比JSP和freemarker之类,简单易用! 今天简单记录一下frag ...

  2. 【linux】/etc/passwd文件

    /etc/passwd文件内容格式 /etc/passwd是保存用户信息的文件. 格式:用户名: 密码 : uid  : gid :用户描述:主目录:登陆shell 举个例子: root:x:0:0: ...

  3. 剑指offer系列51---扑克牌顺子

    [题目]抽五张扑克牌,判断五张扑克牌是不是顺子,大小王可看做任何数,0代替. package com.exe10.offer; import java.util.Arrays; /** * [题目]抽 ...

  4. php base64编码和urlencode

    base64编码 加密 base64_encode($str); 解密 base64_decode(base64_encode($str)); urlencode和base64混合使用 functio ...

  5. [linux basic 基础]----线程的属性

    在信号量和互斥量例子中,我们都是在程序推出之前利用pthread_join对线程进行再次同步:如果想让thread想创建它的线程返回数据我需要这么做:问题:我们有时候既不需要第二个线程向main线程返 ...

  6. Java面试必备知识2

    1 .三个Statment区别,用法 Statement,基本的:PreparedStatement是可编译的,提高效率,callablestatement,存储过程 2 .Cookie 答:临时co ...

  7. Instant Run

    http://tools.android.com/tech-docs/instant-run N Developer Preview users: Instant Run is currently i ...

  8. PLSQL_性能优化系列04_Oracle Optimizer优化器

    2014-09-25 Created By BaoXinjian

  9. DBA_Tablespace表空间的概念和管控(概念)

    2014-07-24 Created By BaoXinjian

  10. 3. Windows根据端口查进程---ADB 相关报错 ADB server didn't ACK cannot bind ':5037'

    1.ADB server didn't ACK,一般报ADB相关的错误,大部分是端口被占用了 处理方法: 在命令行输入>adb nodaemon server 如果返回: cannot bind ...