日常训练题解

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. 51nod_1154 回文串的划分

    说实话..最开始看这题感觉一定好难...好高大上...我的马拉车还不熟....这种..但是本着做不出来也要至少看看的心态,吧个题看完了..然后简单的想了想,好像是个挺直观的动态规划,因为看到数据几乎就 ...

  2. sql中一个服务器建立另一个服务器的连接

    EXEC sp_addlinkedserver 'TonyLink','','SQLOLEDB','111.111.1.111(服务器名)' EXEC sp_addlinkedsrvlogin 'To ...

  3. luogu3338 [ZJOI2014]力

    我发现我的构造方法好像不太一样而且比较显然?--先读入 \(q\) 数组(下表从零开始). 记 \(i < j\) 时,\(a_{i-j}=-1/i^2\):\(i > j\) 时,\(a ...

  4. 56、使用android studio(v1.3.*)修改包名 (rename package name)

    一.修改包名 ①选中目录,开始构造 在弹窗中选中Rename directory 在弹窗中选中Rename package 填写新的包名,点击Refactor 如果有警告,不用管它,直接点击Do Re ...

  5. 了解JavaScript核心精髓(二)

    1.字符串操作 //声明字符串 var str = "abcd"; var str = new String("abcd") //截取字符串 console.l ...

  6. APP网络测试点

  7. [oldboy-django][1初识django]创建虚拟(干净)的Python环境

    如果应用A需要jinja 2.7,而应用B需要jinja 2.6怎么办?此时可以针对不同应用创建不同的虚拟环境. 这种情况下,每个应用可能需要各自拥有一套“独立”的Python运行环境.virtual ...

  8. 【bzoj4439】[Swerc2015]Landscaping 网络流最小割

    题目描述 FJ有一块N*M的矩形田地,有两种地形高地(用‘#’表示)和低地(用‘.’表示) FJ需要对每一行田地从左到右完整开收割机走到头,再对每一列从上到下完整走到头,如下图所示 对于一个4*4的田 ...

  9. BZOJ5306 [HAOI2018]染色 【组合数 + 容斥 + NTT】

    题目 为了报答小 C 的苹果, 小 G 打算送给热爱美术的小 C 一块画布, 这块画布可 以抽象为一个长度为 \(N\) 的序列, 每个位置都可以被染成 \(M\) 种颜色中的某一种. 然而小 C 只 ...

  10. CentOS下Nginx部署React静态应用

    查看CentOS版本: cat /etc/redhat-release 安装nginx: yum install nginx 查看nginx版本: nginx -v 启动nginx: systemct ...