题意

给出一系列数字,判断其中哪三个数字可以构成一个三角形,如果有多个,输出周长最大的那个,如果没有输出 - 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. NetBeans 设置界面语言

    我就懒得吐槽TNND你就不能让用户自己选择语言?这SB中文翻译我也是醉了,尽是误导人 下面的例子用jMonkeyEngine SDK的设置为例子(本质上就是NetBeans) 英文设置: 中文设置:

  2. mock实例方法

    1.Mockito.when(categoryService.queryTopCategory("1")).thenReturn(categories);//返回的是list列表, ...

  3. UIView 实例方法 Instance Methods(转)

    好了,我接着上篇,开始我们的对UIView 实例方法的探索 UIView 实例方法 Instance Methods 初始化一个视图 - (id)initWithFrame:(CGRect)aRect ...

  4. ueditor 控制上传图片的显示尺寸

    使用UEditor的编辑框插入图片的时候,如果图片尺寸比较大,则图片会超出编辑器边框出现滚动条,特别不方便. 解决办法:在ueditor 的 themes 文件夹下有个iframe.css 文件,在该 ...

  5. 开发GPIO驱动的基本套路

    最近完成了基于AR9331的GPIO驱动的开发,主要包括:控制一个连接GPIO的灯控:接收一个连接GPIO的按键事件:以及接收一个连接GPIO的脉冲事件. 这里,结合开发实践,总结一下GPIO驱动开发 ...

  6. 文件存储结构inode与RAM结构建立联系

    linux下一切皆文件,大致可分为以下几类:目录.普通文件.硬连接.软连接.字符设备.块设备.FIFO.Socket,其在物理存储体内存储按inode和数据块存储,inode代表元数据,是除实际数据外 ...

  7. VLC WebPlugin中文

    Documentation:WebPlugin 这篇文档讲述的是 VLC media player Web plugins 和怎样在网页使用它 Contents 1 介绍: 构建包含video的Web ...

  8. js实现点击定位最顶端

    //------------------------------------点击按钮------------------------------------ <span onClick=&quo ...

  9. 我的第二个java程序 循环

    public class Test {//类 public Test (int num){//构造方法,和类同名,无返回值,接收传参并定义传参的类型,大小写敏感 int x = 10;//局部变量,定 ...

  10. CGI(Common Gateway Interface),通用网关接口

    通用网关接口,简称CGI,是一种根据请求信息动态产生回应内容的技术.通过CGI,Web 服务器可以将根据请求不同启动不同的外部程序,并将请求内容转发给该程序,在程序执行结束后,将执行结果作为回应返回给 ...