Codeforces Gym100735 D.Triangle Formation (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)
日常训练题解
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
2
1 1
0
3
2 2 2
1
6
2 2 3 4 5 6
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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 【KTU Programming Camp (Day 3)】Queries
http://codeforces.com/gym/100739/problem/A 按位考虑,每一位建一个线段树. 求出前缀xor和,对前缀xor和建线段树. 线段树上维护区间内的0的个数和1的个数 ...
- KTU Programming Camp (Winter Training Day 1)
A.B.C(By musashiheart) 0216个人赛前三道题解 E(By ggg) Gym - 100735E Restore H(by pipixia) Gym - 100735H
- CodeForcesGym 100735D Triangle Formation
Triangle Formation Time Limit: Unknown ms Memory Limit: 65536KB This problem will be judged on CodeF ...
- Codeforces Round #352 (Div. 2) A. Summer Camp 水题
A. Summer Camp 题目连接: http://www.codeforces.com/contest/672/problem/A Description Every year, hundred ...
- 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 ...
- Codeforces Round #545 (Div. 2)(D. Camp Schedule)
题目链接:http://codeforces.com/contest/1138/problem/D 题目大意:给你两个字符串s1和s2(只包含0和1),对于s1中,你可以调换任意两个字符的位置.问你最 ...
随机推荐
- git pull免密码拉取
ssh到服务器上,原来基于public/private key pair的方法不好使了. 1.1 创建文件存储GIT用户名和密码 在%HOME%目录中,一般为C:\users\Administrato ...
- codeforce GYM 100741 A Queries
A. Queries time limit per test:0.25 s memory limit per test:64 MB input:standard input output:standa ...
- nginx 同一 iP 多域名配置方法(多文件)
一.Nginx 配置文件(nginx version: nginx/1.12.2) 路径:/usr/local/nginx/conf/nginx.conf 操作:在 http 模块增加(子配置文件的路 ...
- c#每循环100次提交一次数据,最后一次不足100次提交一次
StringBuilder sb=new StringBuilder(); string strId=dataGridView1.Rows[dataGridView1.CurrentRow.Index ...
- Strut 2 ValueStack传送带机制
源码与jar包下载(将rar改成jar,直接放在WEB_INF\lib目录中即可) 众所周知,Strut 2的Action类通过属性可以获得所有相关的值,如请求参数.Action配置参数.向其他 ...
- mouseClicked、mousePressed、mouseReleased 的区别
2014年03月16日 21:12:10 xiaobineric 阅读数 9681 标签: 鼠标 事件 关于这3个事件,一直搞不清楚甚至混淆,也已经有一些人说过,但觉得不够明白,最近看了一段教材的 ...
- 【转】ugui自制摇杆
http://www.cnblogs.com/duyushuang/p/4457691.html 珍爱生命,远离插件. 以上8个字,好好理解. 反正我是这么觉得. 我说的是unity,不是魔兽世界. ...
- java替换富文本标签等
(转自:http://www.cnblogs.com/1246447850qqcom/p/5439366.html) package q;import java.util.regex.Matcher; ...
- AGC 26 F Manju Game
$\DeclareMathOperator{\sw}{sw}$ $\DeclareMathOperator{\sb}{sb}$ $\DeclareMathOperator{\dp}{dp}$ 用 $\ ...
- [ZJOI2010][bzoj1834] 网络扩容 [费用流]
题面 传送门 思路 第一问:无脑网络流跑一波 第二问: 先考虑一个贪心的结论:扩容出来的扩容流量一定要跑满 证明显然 因此我们可以把扩容费用可以换个角度思考,变成增加一点流量,花费W的费用 这样,我们 ...