题意

给出一系列数字,判断其中哪三个数字可以构成一个三角形,如果有多个,输出周长最大的那个,如果没有输出 - 1

思路

数据较小,所有情况FOR一遍 判断一下

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream> using namespace std;
typedef long long LL; const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6; const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 50 + 5;
const int MOD = 1e9 + 7; LL a[maxn]; bool judge(LL b[])
{
if (b[0] + b[1] > b[2])
return true;
return false;
} int main()
{
int n;
cin >> n;
LL b[3], ans[3];
LL MAX = MINN;
for (int i = 0; i < n; i++)
scanf("%lld", &a[i]);
sort(a, a + n);
int i, j, k;
for (i = 0; i < n; i++)
{
for(j = i + 1; j < n; j++)
{
for (k = j + 1; k < n; k++)
{
b[0] = a[i];
b[1] = a[j];
b[2] = a[k];
sort(b, b + 3);
if (judge(b))
{
LL temp = b[0] + b[1] + b[2];
if (temp > MAX)
{
for (int l = 0; l < 3; l++)
ans[l] = b[l];
MAX = temp;
}
}
}
}
}
if (MAX != MINN)
{
printf("%lld %lld %lld\n", ans[0], ans[1], ans[2]);
}
else
cout << -1 << endl;
}

HackerRank - maximum-perimeter-triangle 【水】的更多相关文章

  1. LeetCode 976. 三角形的最大周长(Largest Perimeter Triangle) 33

    976. 三角形的最大周长 976. Largest Perimeter Triangle 题目描述 给定由一些正数(代表长度)组成的数组 A,返回由其中三个长度组成的.面积不为零的三角形的最大周长. ...

  2. 【Leetcode_easy】976. Largest Perimeter Triangle

    problem 976. Largest Perimeter Triangle solution: class Solution { public: int largestPerimeter(vect ...

  3. [Swift]LeetCode976. 三角形的最大周长 | Largest Perimeter Triangle

    Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, ...

  4. LeetCode 976 Largest Perimeter Triangle 解题报告

    题目要求 Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero ...

  5. 119th LeetCode Weekly Contest Largest Perimeter Triangle

    Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, ...

  6. 【leetcode】976. Largest Perimeter Triangle

    题目如下: Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero ...

  7. 976. Largest Perimeter Triangle

    Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, ...

  8. 【LeetCode】976. Largest Perimeter Triangle 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcod ...

  9. uva 11059 maximum product(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  10. Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题

    A. Triangle 题目连接: http://codeforces.com/contest/6/problem/A Description Johnny has a younger sister ...

随机推荐

  1. DataUml Design 教程2-实体建模

    DataUml Design 实体建模基于UML类图标准来设计,支持一对一.一对多.多对多关联.模型与开发语言和数据库绑定.1.新建数据模型    1).选择“数据模型” 节点,点击鼠标右键,在菜单中 ...

  2. Java Stream 官方文档翻译

    先立个flag https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html

  3. samba实现文件共享

    很多时候,做嵌入式开发,都是在windows上安装虚拟,在虚拟机中安装Linux操作系统.这个时候,我们经常需要Linux操作系统下有一个目录能在windows下自由访问.要想实现这个功能我们只需要在 ...

  4. 初尝CDN:什么是分布式服务节点?

    什么是CDN?笔者初见时也是摸不着头脑,查阅了大量的资料才明白什么是CDN,笔者为您揭秘什么是CDN? CDN的全称是Content Delivery Network,即内容分发网络.CDN的通俗理解 ...

  5. 解决xshell6评估过期,需采购问题

    2018年12月20日补充 绿色免安装版: https://www.lanzous.com/i2njdre 密码:9b7t 2018年7月18日补充 感谢s***5大佬提供注册包,有需要的小伙伴,请留 ...

  6. 在iframe的父级作用域操作,ifame中的元素。。

    frames["iframe的name"].SchDatas SchDatas为方法名js中 frames["iframe的name"].document.ge ...

  7. day2 python基础 while 循环补充

    一.上节内容回顾 二.pycharm安装. 安装好以后激活方法:直接打开pycharm,选License server激活,输入:http://idea.imsxm.com 三.补充知识:如果字符串本 ...

  8. SSH后台管理系统,实现查询+分页

    一个搜索框,然后会获取大量信息,将信息进行分页,每一页显示固定条数. mysql中使用“like”和“%%”进行模糊匹配,用“limit”进行分页. 1.首先创建一个页面信息的实体类,代码如下: im ...

  9. Observable观察者模式的使用

    今天我们公司封装的类中没有加上Observable观察者模式,但是很多地方需要用到Observable观察者模式 接下来就向大家介绍一下我的使用吧! 在介绍之前我们写了一个方法 public clas ...

  10. Tomcat设置maxPostSize导致Post请求不过去

    问题:最近部署项目,用到的Tomcat 版本:7.0.82.0,发现一直登陆不了,查询发现原来前端的数据传递不到后端 排查问题:通过debug日志发现,后端没有接受到前端用户的登陆数据,检查发现Tom ...