题目描述

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(T≤100) will exist in the first line of input, indicating the number of test cases.
Each test case begins with the number of sticks N(N≤100). The following line contains N numbers length[i]

(1≤length[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

其实是很简单的一题, 不过比赛时NC读错了, 又是一个WA再AC

感觉我WA率略高啊......

题意是找不同的等边三角形个数, 非常懒的排序然后再统计了, 感觉思路拙计时空效率也低

反正这些都是比赛代码, 过了就行, 要效率的话我再重写一个好了= =

话说我也想学C++啊, 为什么我每次都要写qsort的cmp啊, 已经写到不能忍了好么, 坑爹啊(摔

/*
USER_ID: test#birdstorm
PROBLEM: 143
SUBMISSION_TIME: 2014-03-11 00:27:40
*/
#include <stdio.h>
#include <stdlib.h>
#define For(i,m,n) for(i=m;i<n;i++)
#define MAXN 105int a[MAXN], cnt[MAXN];int cmp(const void* a, const void* b)
{return *(int*)a-*(int*)b;
}main()
{int t, i, j, k, n, m, sum;scanf("%d",&t);while(t--){scanf("%d",&n); k=sum=0;For(i,0,n) scanf("%d",&a[i]);For(i,0,n) cnt[i]=1;qsort(a,n,sizeof(int),cmp);For(i,0,n-1){if(a[i]==a[i+1]) cnt[k]++;else k++;}For(i,0,k+1) sum+=(cnt[i]>=3?1:0);printf("%d\n",sum);}return 0;
}

BUPT OJ143 Triangle相关推荐

  1. [JS][C++]两题斐波那契数列:上台阶、triangle

    上台阶 时间限制: 3000MS 内存限制: 589824KB 题目描述: 有一楼梯共m级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第m级,共有多少走法? 注:规定从一级到一级有0种走法. ...

  2. 设计一个扩展自抽象类geometricobject的新的triangle类_C++ 接口(抽象类)

    C++ 接口(抽象类) 接口描述了类的行为和功能,而不需要完成类的特定实现. C++ 接口是使用抽象类来实现的,抽象类与数据抽象互不混淆,数据抽象是一个把实现细节与相关的数据分离开的概念. 如果类中至 ...

  3. 帕斯卡三角形(Pascal's triangle)

    // The following code is compiled on VC2005 // #include "stdafx.h" /*--------------------- ...

  4. [leedcode 118] Pascal's Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  5. [LeetCode 120] - 三角形(Triangle)

    问题 给出一个三角形,找出从顶部至底部的最小路径和.每一步你只能移动到下一行的邻接数字. 例如,给出如下三角形: [ [2], [3,4], [6,5,7], [4,1,8,3] ] 从顶部至底部的最 ...

  6. D - Triangle Partition HDU - 6300 sort(cmp)

    D - Triangle Partition HDU - 6300 题解 由于三点不共线,且三角形不相交,则对坐标排序,输出 #include<bits/stdc++.h> using n ...

  7. Leetcode 118:Pascal's Triangle 杨辉三角

    118:Pascal's Triangle 杨辉三角 Given a non-negative integer numRows, generate the first numRows of Pasca ...

  8. LintCode: Triangle

    C++ 逆推 1 class Solution { 2 public: 3 /** 4 * @param triangle: a list of lists of integers. 5 * @ret ...

  9. [LeetCode]--118. Pascal#39;s Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

最新文章

  1. 印象笔记 还回快捷_模块化编辑器、OCR、素材库...一大波新功能来袭丨印象笔记7周年现场实况...
  2. 的计时器设置_如何选择最适合自己的计时器?
  3. LA 3695 Distant Galaxy
  4. 2017计算机湖北对口试题答案,2017年计算机专业对口考试试卷及答案
  5. 前后端分离的用户验证原理及Spring Boot + JWT的框架搭建(附完整的框架代码)之一
  6. Maven运行报错:-Dmaven.multiModuleProjectDirectory system propery is not set.
  7. 基于vue3 实现页面自动配色、颜色选择器组件
  8. java(6)String Builder和String Joiner
  9. 郑码输入法 字根记忆表 一般根变通处理
  10. 数字图像处理:图像压缩1 基础无损压缩
  11. DeepFM Pytorch实现(Criteo数据集验证)
  12. CTF学习(二)——信息泄露、密码口令、SQL注入、文件上传
  13. Linux操作系统基础之用户管理
  14. 当外面的容器的height使用百分比时,如何设置line-height可以使里面的文字垂直居中
  15. html旋转线条,html5 – 为什么我在移动浏览器上看到旋转的条纹?
  16. nyoj1238 最少换乘 最短路
  17. CSS #38; JS
  18. js 将微信二维码转为url,qrcodeJs解析二维码,qrcode.decode is not a function报错
  19. sqli-labs靶场challenges第54-75关(超详细)
  20. 如何防止网站被恶意骚扰

热门文章

  1. CVE-2019-11478 Sack SlownessExcess Resource Usage漏洞解析与利用
  2. 面试时应该如何进行自我介绍呢
  3. m3u8.sqlite转mp4(txkt,文末附程序下载地址)
  4. 小D的一串数字(简单DP)
  5. 10027Longest Ordered Subsequence Extention
  6. 感冒发烧没想象中可怕:人体自我保护清除体内感染
  7. vuejs实现购物车满多少减多少
  8. 洛谷P4643 [国家集训队]阿狸和桃子的游戏
  9. 什么是arXiv.org?
  10. 用Python写了个工具,完美破解了MySQL!!(建议收藏)