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 ...
随机推荐
- R(五): R常用函数
工作笔记记录,会持续更新.... 目录: apply tapply lapply sapply merge substr.substring.strsplit.unlist.paste.paste0. ...
- 09Socket编程
tcp是基于字节流的,udp是基于报文即数据包的,所以tcp会产生一个叫做粘包的问题,而udp不会产生. 我们这节主要讨论粘包问题: 先看一下粘包问题的原因: 总结如下: 1.应用进程的缓冲区和Soc ...
- HackerRank "Dorsey Thief"
A variation to 0-1 Knapsack. (No Python code got fully AC. Python is too slow for this problem) #inc ...
- 【转】Java HashMap 源码解析(好文章)
.fluid-width-video-wrapper { width: 100%; position: relative; padding: 0; } .fluid-width-video-wra ...
- gdb: multiple process debug
gdbserver自身不支持multiple process:如果你调试parent process时在子进程上下断点,子进程在运行到那个断点时就会SIGTRAP. 如果你要调试fork出来的子进程: ...
- IntelliJ IDEA自动去掉行尾空格
Settings→Editor→General 先选中Allow placement of caret after end of line 再修改Strip trailing spaces on Sa ...
- memcache 永久数据被踢
1.memcache的slab chunk 就像公交车的坐位一样,有大小之分,还有活跃的状态. 2.代码 index.php -->插入数据,注意$value的大小和重复次数,跟chunk和其数 ...
- Tomcat在eclipse中起动成功,主页却打不开
症状: tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080/不能访问,且报404错误.同时其他项目页面也不能访问. 关闭eclipse里面的tomc ...
- Linux系统默认服务建议开启关闭说明列表
服务名称 功能简介 建议 acpid 电源管理接口.如果是笔记本用户建议开启,可以监听内核层的相关电源事件. 开启 anacron 系统的定时任务程序.cron的一个子系统,如果定时任务错过了执行时间 ...
- ADF_General JSF系列2_创建JSF类型的页面向导
2015-02-17 Created By BaoXinjian