zoukankan      html  css  js  c++  java
  • 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

    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
    ");
    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
    ",num);
    30         }
    31     }
    32     return 0;
    33 }

    溜了溜了。。。

  • 相关阅读:
    【Linux常用命令】 cat
    【Linux常用命令】 chmod
    【2012.4.22】北京植物园&卧佛寺
    【Linux常用命令】 重定向输出 > 和 >>
    一些话
    linux下查看用户个数和具体名字
    【Linux常用命令】 ls
    Ethernet frame
    防止修改类和方法
    redis数据批量导入导出
  • 原文地址:https://www.cnblogs.com/ZERO-/p/8329420.html
Copyright © 2011-2022 走看看