日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

计算输入序列能组成三角形的个数

發(fā)布時間:2023/12/18 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 计算输入序列能组成三角形的个数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

B. Triangle 第八屆北京郵電大學(xué)程序設(shè)計競賽 - 熱身賽 (2)

時間限制 1000 ms 內(nèi)存限制 65536 KB

題目描述

Amy learned equilateral triangle today and was interested in it very much. After school, she took out her toys as usual and surprisingly found so many sticks! As the plot goes, she started to count how many different equilateral triangles they could form. However, there're countless sticks and it was not easy for such a little girl to finish this task. Help her!
An equilateral triangle is such a triangle, that the length of its three sides are equal. Two equilateral triangle are different if and only if they have different lengths of sides. Amy only uses one stick to form one side of a triangle.

?

輸入格式

The input contains several cases. An integer T(T100) will exist in the first line of input, indicating the number of test cases.
Each test case begins with the number of sticks N(N100). The following line contains N numbers length[i]

(1length[i]100), indicating all the lengths of sticks.

輸出格式

Output the answer for each test case in respective lines.
?

輸入樣例

2 3 2 3 1 4 3 3 3 3

輸出樣例

0 1

一個測試通過代碼:

#include <iostream>
#include <map>
using namespace std;

int solution(int *org, int len)
{
??? int res = 0;
??? map<int, int> data;
??? for (int i = 0; i < len; ++i) {
??????? data[org[i]]++;
??? }
??? map<int, int>::iterator itr = data.begin();
??? while (itr != data.end()) {
??????? if (itr->second >= 3)
??????????? ++res;
??????? ++itr;
??? }
??? return res;
}

int main()
{
??? int t;
??? cin >> t;
??? for (int i = 0; i < t; ++i) {
??????? int n;
??????? cin >> n;
??????? int *data = new int[n];
??????? for (int j = 0; j < n; ++j) {
??????????? cin >> data[j];
??????? }
??????? cout << solution(data, n) << endl;
??????? delete [] data;
??? }
??? return 0;
}

轉(zhuǎn)載于:https://www.cnblogs.com/candycloud/p/3591788.html

總結(jié)

以上是生活随笔為你收集整理的计算输入序列能组成三角形的个数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。