7144. Different Triangles 回校第一天 来个水题

7144. Different Triangles

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

 

Given N sticks of different length, please find out how many different ways you can form a triangle by three of these sticks.

Input

The first line contains an integer T (T<=20), indicating the number of test cases. Each case contains two lines. The first line contains an integer N (3<=N<=100). The second line contains N different positive integers not greater than 1000, indicating the lengths of sticks.

Output

 

For each case, output the number of ways to form a triangle.

Sample Input

231 2 342 3 4 5

Sample Output

03

Hint

In the second sample, you can form a triangle using (2, 3, 4), (2, 4, 5) or (3, 4, 5).

Problem Source

“星海通杯”第四届中山大学ICPC新手赛 by 林瀚


#include <iostream>

using namespace std;

int main () {
	int T;
	cin>>T;
	while (T--) {
		int N;
		cin>>N;
		int a[101];
		for (int i = 0; i < N; i++) {
			cin>>a[i];
		}
		int p;
		int q;
		int r;
		int count = 0;
		bool flag = true;
		for (p = 0; p < N - 2; p++) {
			for (q = p + 1; q < N - 1; q++) {
				for (r = q + 1; r < N; r++) {
					if (a[p] + a[q] <= a[r] || a[p] + a[r] <= a[q] || a[r] + a[q] <= a[p]) {
						flag = false;
					}
					if (flag == true)
						count++;
					flag = true;
				}
			}
		}
		cout<<count<<endl;
	
	}

	//system("pause");
	return 0;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值