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 shell 脚本30分钟教程
    ubuntu nginx+mysql+php 服务器环境自动配置脚本
    前端开发中常用工具函数总结
    经常逛的技术网站
    简单好用的在线思维导图工具
    在线短信接收
    一些图片站
    常用CSS媒体查询
    Dart Language samples
    IDEA 快捷键
  • 原文地址:https://www.cnblogs.com/ZERO-/p/8329420.html
Copyright © 2011-2022 走看看