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 ...
随机推荐
- golang的推荐的orm库
https://github.com/jinzhu/gorm
- CSS3字体图标
网址:http://icomoon.io/http://iconfont.cn/ 阿里巴巴字体库 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...
- win7 Android环境搭配
Eclipse环境 第一步:下载JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.h ...
- OpenGL®ES基础
参考:http://www.cnblogs.com/salam/archive/2016/01/08/5113572.html http://blog.csdn.net/wangyuchun_799/ ...
- PLSQL_解析过程及硬解析和软解析的区别(案例)
2014-08-11 Created By BaoXinjian
- AP_AP系列 - 供应商管理(案例)
2014-07-03 Created By BaoXinjian
- c语言知识(2)
while(n)首先,n在这里被当作了一个条件其次,当n为真时,进入while循环体(A):否则跳出循环继续执行下面部分(B).n为0时条件为假 n不为0条件为真 while(j) { if(j%1 ...
- JMeter使用技巧
在这此对新版本jmeter的学习+温习的过程,发现了一些以前不知道的功能,所以,整理出来与大分享.本文内容如下. 如何使用英文界面的jmeter 如何使用镜像服务器 Jmeter分布式测试 启动Deb ...
- RPC介绍
转载http://blog.csdn.net/mindfloating/article/details/39474123/ 近几年的项目中,服务化和微服务化渐渐成为中大型分布式系统架构的主流方式,而 ...
- 如何利用jQuery进行简单表单验证
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name=&qu ...