Triangular Collection思维

简介: 题目描述Call a set of positive integers triangular if it has size at least three and, for all triples of distinct integers from the set, a triangle with those three integers as side lengths can be constructed.Given a set of positive integers, compute the number of its triangular subsets.

题目描述


Call a set of positive integers triangular if it has size at least three and, for all triples of distinct integers from the set, a triangle with those three integers as side lengths can be constructed.

Given a set of positive integers, compute the number of its triangular subsets.

输入


The first line of input contains a single integer n (1 ≤ n ≤ 50), which is the number of integers in the set.

Each of the the next n lines contains a single integer x (1 ≤ x ≤ 109 ). These are the elements of the set. They are guaranteed to be distinct.

输出


Output a single integer, which is the number of triangular subsets of the given set.


样例输入 Copy


【样例1】

5
3
1
5
9
10


【样例2】

10
27
26
17
10
2
14
1
12
23
39


样例输出 Copy


【样例1】

2

【样例2】

58


题意:


求出集合的个数,这些集合要满足,在该集合中任意选三个点可以构成三角形


将所有的边长进行按照从小到大进行排序之后,枚举两条边的起点和终点,然后计算出这两条边的和,求出在排序后的数组中在(a[j],sum)之间的能够组成的子集的数量进行计算,对于n个点,有2n - 1种选择方式

int n, m, k;
ll a[maxn];
int main() {
    n = read;
    ll ans = 0;
    for (int i = 1; i <= n; i++) a[i] = read;
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; i++) {
        for (int j = 1 + i; j <= n; j++) {
            ll sum = a[i] + a[j];
            int p = n;
            while (a[p] >= sum) p--;
            ans += (1LL << (p - j));
            ans --;
        }
    }
    cout << ans << endl;
    return 0;
}



目录
相关文章
|
安全
分子构象Molecular Conformation
分子构象(Molecular Conformation),也称分子构型,是指分子在空间中的排列方式和形态。分子构象的不同可以导致分子在物理、化学和生物学等方面表现出不同的性质和行为,因此分子构象的研究对于理解和预测分子性质和行为具有重要意义。
285 1
UVa1584 - Circular Sequence
UVa1584 - Circular Sequence
36 0
|
Java Unix Shell
Regular Expressions (9)
基于POSIX BRE & ERE
181 0
Regular Expressions (9)
Angular Feature Modules
Angular Feature Modules
113 0
LeetCode 622:设计循环队列 Design Circular Queue
LeetCode 622:设计循环队列 Design Circular Queue 首先来看看队列这种数据结构: 队列:先入先出的数据结构 在 FIFO 数据结构中,将首先处理添加到队列中的第一个元素。
968 0
Angular 的概念模型
既然如此,问题就来了,新版本的 Angular 的核心概念是什么呢? 非常简单,一切都是围绕着“组件”( Component )的概念展开的: enter image description here Component(组件)是整个框架的核心,也是终极目标。
732 0