UVA 12651 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 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的更多相关文章
- uva 12508 - Triangles in the Grid(几何+计数)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/35244875 题目链接:uva 12508 ...
- UVA 12508 - Triangles in the Grid(计数问题)
12508 - Triangles in the Grid 题目链接 题意:给定一个n∗m格子的矩阵,然后给定A,B.问能找到几个面积在A到B之间的三角形. 思路:枚举每一个子矩阵,然后求[0,A]的 ...
- UVA 12075 - Counting Triangles(容斥原理计数)
题目链接:12075 - Counting Triangles 题意:求n * m矩形内,最多能组成几个三角形 这题和UVA 1393类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对 ...
- uva 11275 3D Triangles (3D-Geometry)
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= ...
- uva 11275 3D Triangles
题意:三维空间中,给出两个三角形的左边,问是否相交. 面积法判断点在三角形内: #include<cstdio> #include<cmath> #include<cst ...
- UVA 12075 Counting Triangles
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- UVA 1393 Highways,UVA 12075 Counting Triangles —— (组合数,dp)
先看第一题,有n*m个点,求在这些点中,有多少条直线,经过了至少两点,且不是水平的也不是竖直的. 分析:由于对称性,我们只要求一个方向的线即可.该题分成两个过程,第一个过程是求出n*m的矩形中,dp[ ...
- uva 11178 - Morley's Theorem
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- Count the number of possible triangles
From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...
随机推荐
- thymeleaf之fragment
MUEAS项目,web前端采用thymeleaf作为展示层.这个view解析器,个人觉得非常不错.简单而且性能也比较好!个人觉得比JSP和freemarker之类,简单易用! 今天简单记录一下frag ...
- 【linux】/etc/passwd文件
/etc/passwd文件内容格式 /etc/passwd是保存用户信息的文件. 格式:用户名: 密码 : uid : gid :用户描述:主目录:登陆shell 举个例子: root:x:0:0: ...
- 剑指offer系列51---扑克牌顺子
[题目]抽五张扑克牌,判断五张扑克牌是不是顺子,大小王可看做任何数,0代替. package com.exe10.offer; import java.util.Arrays; /** * [题目]抽 ...
- php base64编码和urlencode
base64编码 加密 base64_encode($str); 解密 base64_decode(base64_encode($str)); urlencode和base64混合使用 functio ...
- [linux basic 基础]----线程的属性
在信号量和互斥量例子中,我们都是在程序推出之前利用pthread_join对线程进行再次同步:如果想让thread想创建它的线程返回数据我需要这么做:问题:我们有时候既不需要第二个线程向main线程返 ...
- Java面试必备知识2
1 .三个Statment区别,用法 Statement,基本的:PreparedStatement是可编译的,提高效率,callablestatement,存储过程 2 .Cookie 答:临时co ...
- Instant Run
http://tools.android.com/tech-docs/instant-run N Developer Preview users: Instant Run is currently i ...
- PLSQL_性能优化系列04_Oracle Optimizer优化器
2014-09-25 Created By BaoXinjian
- DBA_Tablespace表空间的概念和管控(概念)
2014-07-24 Created By BaoXinjian
- 3. Windows根据端口查进程---ADB 相关报错 ADB server didn't ACK cannot bind ':5037'
1.ADB server didn't ACK,一般报ADB相关的错误,大部分是端口被占用了 处理方法: 在命令行输入>adb nodaemon server 如果返回: cannot bind ...