日常训练题解

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 ;
}

溜了溜了。。。

Codeforces Gym100735 D.Triangle Formation (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)的更多相关文章

  1. Codeforces Gym100735 G.LCS Revised (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)

    G.LCS Revised   The longest common subsequence is a well known DP problem: given two strings A and B ...

  2. Codeforces Gym100735 I.Yet another A + B-Java大数 (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)

    I.Yet another A + B You are given three numbers. Is there a way to replace variables A, B and C with ...

  3. Codeforces Gym100735 E.Restore (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)

    E - Restore Given a matrix A of size N * N. The rows are numbered from 0 to N-1, the columns are num ...

  4. 【KTU Programming Camp (Day 3)】Queries

    http://codeforces.com/gym/100739/problem/A 按位考虑,每一位建一个线段树. 求出前缀xor和,对前缀xor和建线段树. 线段树上维护区间内的0的个数和1的个数 ...

  5. KTU Programming Camp (Winter Training Day 1)

    A.B.C(By musashiheart) 0216个人赛前三道题解 E(By ggg) Gym - 100735E Restore H(by pipixia) Gym - 100735H

  6. CodeForcesGym 100735D Triangle Formation

    Triangle Formation Time Limit: Unknown ms Memory Limit: 65536KB This problem will be judged on CodeF ...

  7. Codeforces Round #352 (Div. 2) A. Summer Camp 水题

    A. Summer Camp 题目连接: http://www.codeforces.com/contest/672/problem/A Description Every year, hundred ...

  8. Codeforces Round #352 (Div. 2) A Summer Camp

    Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard proble ...

  9. Codeforces Round #545 (Div. 2)(D. Camp Schedule)

    题目链接:http://codeforces.com/contest/1138/problem/D 题目大意:给你两个字符串s1和s2(只包含0和1),对于s1中,你可以调换任意两个字符的位置.问你最 ...

随机推荐

  1. POJ 2586 贪心+枚举

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15626   Accepted: 78 ...

  2. Uva:11401-Triangle Counting

    Triangle Counting Time limit1000 ms Description You are given n rods of length 1, 2-, n. You have to ...

  3. 库函数的使用:sscanf的使用方法

    先贴代码,可以看懂代码的直接看代码: /***************************************************** ** Name : sscanf.c ** Auth ...

  4. 菜鸟学Linux - 用户与用户组基础

    /etc/passwd: 用户的信息是保存在/etc/passwd下面(早期的时候,用户的密码也是放在该文件中.后来出于安全考虑,将密码放在/etc/shadow中去): /etc/group: 用户 ...

  5. PowerShell批量启动/关闭Azure VM

    备注:以下例子中出现的JohnsonWeb, JohnsonVm均是虚拟机的名称.在运行Powershell脚本之前,请导入您的订阅文件. 根据条件启动/关闭虚拟机,例如根据虚拟机名称,批量启动/关闭 ...

  6. billard:桌球的走位路线图解

    这些是桌球的一些基础知识,记得刚学会桌球那会儿很强烈的想找到类似图片或资料,好久都找不到,最严重的时候只要一闭上眼睛,满脑子就是桌球的路线,线路图几乎是无处不在,痛苦的是经常能理解过来的很多路线因为杆 ...

  7. React基础(Diff算法,属性和状态)

    1.React的背景原理 (1)React Diff算法流程 (2)React虚拟DOM机制 React引入了虚拟DOM(Virtual DOM)的机制:在浏览器端用Javascript实现了一套DO ...

  8. JMeter非GUI界面运行

    JMeter是一款可以用于做接口可以用于作压力性能的应用程序,该程序是纯Java语音开发,所有对环境支持都比较好. JMeter可以运行模式有两种,一种是UI图形,另一种是命令模式运行也就是非GUI模 ...

  9. idea使用maven逆向mybitis的文件

    引用自 http://blog.csdn.net/for_my_life/article/details/51228098 本文介绍一下用Maven工具如何生成Mybatis的代码及映射的文件. 一. ...

  10. Map 的两种遍历方法详细说明

    //方法一 Set<String> set = map.keySet(); for (String s:set) { System.out.println(s+","+ ...