腾讯9.18笔试

第三题,求合法三角形个数
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{

int t;
cin >> t;
vector<int> res;//记录结果
for (int i = 0; i < t; i++)
{
vector<int> a;
int k;
cin >> k;
for (int j = 0; j < k; j++)
{
int tmpnumber;
cin >> tmpnumber;
a.push_back(tmpnumber);
}
sort(a.begin(), a.end());

int len = a.size();

int pos1 = 0, pos2 = 1, pos3 = 3;
int cnt=0;//记录个数

while (pos3 < len)
{
if (a[pos1] + a[pos2] > a[pos3])
{

cnt++;
}

if (pos1 + 1 < pos2)
{
pos1++;
}
else
if (pos2 + 1 < pos3)
{
pos2++;
}
else
{
pos3++;
}

}
res.push_back(cnt);
}

for (auto i = res.begin(); i != res.end(); i++)
{
cout << *i << endl;
}

system("pause");
}

#腾讯#
全部评论

相关推荐

10-13 22:56
门头沟学院 C++
rt,鼠鼠的浪潮网签明天过期,鼠鼠是山东人,好像自己也能接受。之前的面试大厂基本挂干净了,剩下小米二面后在泡,问了下面试官没有挂,但要泡。还有海信似乎也通过了,不过在深圳,鼠鼠也不是很想去。其它还有一些公司应该陆陆续续还有一些面试,现在有些纠结是直接签了还是再等再面呢?大佬们能不能给鼠鼠提一些意见,万分感谢!!!
牛客78696106...:浪潮可不是开摆,当初我还是开发的时候我组长跟我说他们组有段时间天天1,2点走,早上5点就来,全组肝出来心肌炎,浪潮挣钱省立花可不是说说,当然也看部门,但是浪潮普遍就那dio样,而且你算下时薪就知道不高,没事也是9点半走,不然算你旷工
投递小米集团等公司10个岗位
点赞 评论 收藏
分享
牛客40297450...:不是研究生强,是你强
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务