Codeforces Gym100735 D.Triangle Formation (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, Augus...

日常训练题解

 

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

 

暴力就可以了

 

代码:

 1 #include<cstring>
 2 #include<cstdio>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 int a[50],flag[50];
 7 int main(){
 8     int n;
 9     while(~scanf("%d",&n)){
10         memset(flag,0,sizeof(flag));
11         for(int i=0;i<n;i++){
12             scanf("%d",&a[i]);
13             flag[i]=1;
14         }
15         sort(a,a+n);
16         if(n<=2)printf("0\n");
17         else{
18             int num=0;
19             for(int i=0;i<n;i++){
20                 for(int j=0;j<n;j++){
21                     for(int k=0;k<n;k++){
22                         if(i!=j&&i!=k&&j!=k&&flag[i]==1&&flag[j]==1&&flag[k]==1&&a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[k]+a[j]>a[i]){
23                             num++;flag[i]=0;flag[j]=0;flag[k]=0;
24                         }
25                         else continue;
26                     }
27                 }
28             }
29             printf("%d\n",num);
30         }
31     }
32     return 0;
33 }

 

 

 

 

溜了溜了。。。

 

 

转载于:https://www.cnblogs.com/ZERO-/p/8329420.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值