日常训练题解

D.Triangle Formation

You are given N wooden sticks. Your task is to determine how many triangles can be made from the given sticks without breaking them. Each stick can be used in at most one triangle.

Input

The first line of each test case contains the number of sticks N. (1 ≤ N ≤ 15)

The second line of each test case contains N integers leni that are the lengths of the sticks. (1 ≤ leni ≤ 109).

Output

Output single integer R – the maximal number of triangles.

Example

Input
2
1 1
Output
0
Input
3
2 2 2
Output
1
Input
6
2 2 3 4 5 6
Output
2

暴力就可以了

代码:

 #include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[],flag[];
int main(){
int n;
while(~scanf("%d",&n)){
memset(flag,,sizeof(flag));
for(int i=;i<n;i++){
scanf("%d",&a[i]);
flag[i]=;
}
sort(a,a+n);
if(n<=)printf("0\n");
else{
int num=;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
for(int k=;k<n;k++){
if(i!=j&&i!=k&&j!=k&&flag[i]==&&flag[j]==&&flag[k]==&&a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[k]+a[j]>a[i]){
num++;flag[i]=;flag[j]=;flag[k]=;
}
else continue;
}
}
}
printf("%d\n",num);
}
}
return ;
}

溜了溜了。。。

最新文章

  1. MVC采用Jquery实现局部刷新
  2. 了解Android的编译器
  3. jmeter ForEach Controller学习
  4. jboss EAP 6.2 + Message Drive Bean(MDB) 整合IBM Webshpere MQ 7.5
  5. HDU 4940 Destroy Transportation system(无源汇有上下界最大流)
  6. lua weak table 概念解析
  7. (8)分布式下的爬虫Scrapy应该如何做-图片下载(源码放送)
  8. MySQL 使用mysqld_multi部署单机多实例详细过程 (转)
  9. shuffle过程中的信息传递
  10. ios开发-确定/自适应textView的高度
  11. c语言学习之基础知识点介绍(八):函数的基本用法
  12. Android Studio显示行数
  13. mybatis延迟加载详解
  14. IOS开发证书常见问题
  15. md
  16. java数组知识点总结
  17. Linux基础命令---chfn
  18. Eclipse下SpringBoot没有自动加载application.properties文件
  19. shonc-聊天im工具配置
  20. Vue脚手架搭建步骤

热门文章

  1. codeforces 258D DP
  2. UVA1484 Alice and Bob&#39;s Trip (hdu3660)
  3. BZOJ 1531: [POI2005]Bank notes
  4. 1497: [NOI2006]最大获利(最大权闭合子图)
  5. 组装需要的json数据格式
  6. 【Gray Code】cpp
  7. 【Remove Duplicates from Sorted Array】cpp
  8. Halcon18 Mac os 下载
  9. Vue在tradingView遇到的问题
  10. [oldboy-django][2深入django]学生管理(Form)-- 添加(美化Form表单:通过form给前端标签添加属性)