[ACM]三角形

</pre><div></div><h3 style="font-family:'Times New Roman',Times,serif; font-size:17px; margin:8px auto; color:rgb(26,92,200)"></h3><h3 style="font-family:'Times New Roman',Times,serif; font-size:17px; margin:8px auto; color:rgb(26,92,200)">Input</h3><div id="proinput" style="width:960px; margin:0px 0px 0px 20px; line-height:1.4em; font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px">题目有多组数据,对于每组数据,第一行为一个整数n(3<=n<=100)代表棍子的数量,接下来一行为n个棍子的长度,长度的范围为1到100000.</div><h3 style="font-family:'Times New Roman',Times,serif; font-size:17px; margin:8px auto; color:rgb(26,92,200)">Output</h3><div id="prooutput" style="width:960px; margin:0px 0px 0px 20px; line-height:1.4em; font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px">对于每组数据输出方案数。</div><h3 style="font-family:'Times New Roman',Times,serif; font-size:17px; margin:8px auto; color:rgb(26,92,200)">Sample Input</h3><div id="prosamplein" style="width:960px; margin:0px 0px 0px 20px; line-height:1.4em; font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px"><pre style="background-color:rgb(245,245,245)">4
1 2 3 4
3
1 2 3

Sample Output

1
0

 
#include<iostream>
using namespace std;
void QuickSort(int e[], int first, int end)
{
	int i = first, j = end;
	int temp = e[first];//记录第一个数据  

	while (i<j)
	{
		while (i<j && e[j] >= temp)  //与first数据比较,右边下标逐渐左移  
			j--;

		e[i] = e[j];

		while (i<j && e[i] <= temp)  //与first数据比较,左边下标逐渐右移  
			i++;

		e[j] = e[i];
	}
	e[i] = temp;                      //将first数据放置于i=j处  

	if (first<i - 1)
		QuickSort(e, first, i - 1);
	if (end>i + 1)
		QuickSort(e, i + 1, end);
}

void main()
{
	int n;
	while (cin>>n)
	{
		int count=0;
		int *len = new int[n];
		for (int i = 0; i < n; i++) cin >> len[i];
		QuickSort(len, 0, n-1);
		for (int a = 0; a < n; a++)
		{
			for (int b = a+1; b < n; b++)
			{
				for (int c = b+1; c < n; c++)
				{
					if (len[a]+len[b]>len[c])
						count++;
					else break;
				}
			}
		}
		cout << count << endl;
	}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值