Codeforces Gym100735 D.Triangle Formation (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)
2024-09-30 02:43:46
日常训练题解
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 ;
}
溜了溜了。。。
最新文章
- MVC采用Jquery实现局部刷新
- 了解Android的编译器
- jmeter ForEach Controller学习
- jboss EAP 6.2 + Message Drive Bean(MDB) 整合IBM Webshpere MQ 7.5
- HDU 4940 Destroy Transportation system(无源汇有上下界最大流)
- lua weak table 概念解析
- (8)分布式下的爬虫Scrapy应该如何做-图片下载(源码放送)
- MySQL 使用mysqld_multi部署单机多实例详细过程 (转)
- shuffle过程中的信息传递
- ios开发-确定/自适应textView的高度
- c语言学习之基础知识点介绍(八):函数的基本用法
- Android Studio显示行数
- mybatis延迟加载详解
- IOS开发证书常见问题
- md
- java数组知识点总结
- Linux基础命令---chfn
- Eclipse下SpringBoot没有自动加载application.properties文件
- shonc-聊天im工具配置
- Vue脚手架搭建步骤
热门文章
- codeforces 258D DP
- UVA1484 Alice and Bob&#39;s Trip (hdu3660)
- BZOJ 1531: [POI2005]Bank notes
- 1497: [NOI2006]最大获利(最大权闭合子图)
- 组装需要的json数据格式
- 【Gray Code】cpp
- 【Remove Duplicates from Sorted Array】cpp
- Halcon18 Mac os 下载
- Vue在tradingView遇到的问题
- [oldboy-django][2深入django]学生管理(Form)-- 添加(美化Form表单:通过form给前端标签添加属性)