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 ...
随机推荐
- Android退出程序时的"再按一次退出"实现
android 个人觉得当用户按下后退键时,出现"再按一次退出"的提示防止误操作比弹出一个对话框是会更人性化的.话不多说上代码: 第一种:重写onKeyDown来监听: long ...
- shopex用户登陆错误提示在nginx下乱码问题
http://www.test.cn/passport-aHR0cDosLHd3dy54eTAwNy5jbixwYXNzcG9ydC1hSFIwY0Rvc0xIZDNkeTU0ZVRBd055NWpi ...
- SPOJ #4 Transform the Expression
Not hard to know it is simply transform from in-order to post-order.My first idea is to build a tree ...
- Redis-sentinel监控
Sentinel介绍 Redis的 Sentinel 系统用于管理多个Redis服务器, 该系统执行以下三个任务: 监控(Monitoring) 提醒(Notification) 自动故障迁移(Aut ...
- bzoj4561: [JLoi2016]圆的异或并
Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面 积并.异或面积并为:当一片区域在奇数个圆内则计算其面积,当一片区域在偶数个 ...
- 关于snprintf的一个warning
在编一段代码时用到snprintf,有个很奇怪的warning 编译提示: warning C4013: 'snprintf' undefined; assuming extern returning ...
- Highcharts 功能强大、开源、美观、图表丰富、兼容绝大多数浏览器的纯js图表库
http://www.hcharts.cn/index.php 暂无介绍,等待后续补充
- HTTP协议的安全性--全站HTTPS
HTTP Basic Authentication很容易让攻击者监听并获取用户名密码.使用Base64来encode用户名密码也只是为将用户名和口令中的不兼容字符转换为均与HTTP协议兼容的字符集. ...
- Form_Form Builder开发基于视图页面和自动代码生成包(案例)
2014-01-06 Created By BaoXinjian
- Edmonds_Karp 算法入门详解(转)
转载自:http://blog.csdn.net/hsqlsd/article/details/7862903 有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点,通常规定为1号点.另一个点也 ...