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 ...
随机推荐
- Java ArrayList操作
import java.util.ArrayList; import java.util.List; import java.util.Iterator; public class Study { p ...
- 05 Linux下开发JSP项目(Hello world)
测试环境: 主机系统:Win 7 虚拟机:VMware workstation 11.1.0 虚拟机OS: centos 6.5 64位 Kernel 2.6.32-431-e16.x86_64 My ...
- VS2013 启动时遇到空白窗口
安装了VS2013 ,然后打开,遇到空白窗口,等了10几秒无果. 我先是修复了VS2013,然后再打开VS2013,则显示登录微软账号的窗口.修复完2013时正好18:08,可能是下班了可以上网,才正 ...
- SQL SERVER 2008安装时出现不能在控件上调用 Invoke 或 BeginInvoke错误 解决方法
或者 SQL SERVER 2008安装时要求重启,但重启后仍要求重启.都可以使用此方法. 注册表的 "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet ...
- form 转json,将form表单中的数据序列化数组后转换为Json
页面中引用了jquery,第一想到的就是序列化,但是序列化后的表单字段为a=1&b=2这种. 这里写一个jquery的扩展方法 $.fn.serializeObject = function( ...
- db4o种纯对象数据库引擎
db4o是一种纯对象数据库,相对于传统的关系数据库+ORM,db4o具有以下好处:1)以存对象的方式存取数据(废话--,不过你考虑一下完全以对象的方式去考虑数据的存取对传统的数据库设计思维来说是多么大 ...
- CPU GPU天梯图
2014年2月
- Spring MVC 教程,快速入门,深入分析
http://elf8848.iteye.com/blog/875830/ Spring MVC 教程,快速入门,深入分析 博客分类: SPRING Spring MVC 教程快速入门 资源下载: ...
- 使用mongo-java-driver3.0.2.jar和mongodb3.0在java代码中的用户验证4
以下是使用mongo-java-driver3.0.2.jar和mongodb3.0.4在java代码中的用户验证: ServerAddress sa = new ServerAddress(host ...
- 最大流问题Ford-Fulkerson方法(转)
本篇主要讲解最大流问题的Ford-Fulkerson解法.可是说这是一种方法,而不是算法,因为它包含具有不同运行时间的几种实现.该方法依赖于三种重要思想:残留网络,增广路径和割.本文将会详细介绍这些内 ...