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;
}



目录
相关文章
|
2天前
|
JavaScript 前端开发 架构师
Angular进阶:理解RxJS在Angular应用中的高效运用
RxJS(Reactive Extensions for JavaScript)是JavaScript的一个响应式编程库,特别适用于处理异步数据流。
10 0
|
7月前
|
JavaScript 前端开发 编译器
Angular 里的 Module 增强
Angular 里的 Module 增强
31 0
|
8月前
关于 Angular 应用 Module 的 forRoot 方法的讨论
关于 Angular 应用 Module 的 forRoot 方法的讨论
44 0
|
8月前
|
JavaScript 前端开发 编译器
关于 index.ts 在大型 Angular 项目中的应用
关于 index.ts 在大型 Angular 项目中的应用
51 0
|
9月前
UVa1584 - Circular Sequence
UVa1584 - Circular Sequence
24 0
|
Java Unix Shell
Regular Expressions (9)
基于POSIX BRE & ERE
143 0
Regular Expressions (9)
|
JSON JavaScript 前端开发
Angular 开发中的 Source Map
Angular 开发中的 Source Map
117 0
Angular 开发中的 Source Map
|
开发者
Angular ngTemplateOutlet 元素的学习笔记
Angular ngTemplateOutlet 元素的学习笔记
97 0
Angular ngTemplateOutlet 元素的学习笔记
|
编译器 网络架构
Angular 不同种类 Module 的介绍
Angular 不同种类 Module 的介绍
129 0
Angular 不同种类 Module 的介绍