HackerRank - maximum-perimeter-triangle 【水】
题意
给出一系列数字,判断其中哪三个数字可以构成一个三角形,如果有多个,输出周长最大的那个,如果没有输出 - 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 【水】的更多相关文章
- LeetCode 976. 三角形的最大周长(Largest Perimeter Triangle) 33
976. 三角形的最大周长 976. Largest Perimeter Triangle 题目描述 给定由一些正数(代表长度)组成的数组 A,返回由其中三个长度组成的.面积不为零的三角形的最大周长. ...
- 【Leetcode_easy】976. Largest Perimeter Triangle
problem 976. Largest Perimeter Triangle solution: class Solution { public: int largestPerimeter(vect ...
- [Swift]LeetCode976. 三角形的最大周长 | Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, ...
- LeetCode 976 Largest Perimeter Triangle 解题报告
题目要求 Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero ...
- 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, ...
- 【leetcode】976. Largest Perimeter Triangle
题目如下: Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero ...
- 976. Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, ...
- 【LeetCode】976. Largest Perimeter Triangle 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcod ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题
A. Triangle 题目连接: http://codeforces.com/contest/6/problem/A Description Johnny has a younger sister ...
随机推荐
- 怎样正确写网站title、keywords、description比较标准。
一.title title,也就是标题,是在浏览器上面显示出来的,方便用户了解这个页面的内容;特别是搜索引擎判断你网页内容的主要根据.搜索引擎就很大部分是依靠网站title来判断你网站是关于什么内容的 ...
- 关于Python的Object继承
今天在Coding的使用,使用了python的单例模式,发现了一个很有趣的问题. class x(object): __se = None a = None def __new__(cls): if ...
- Ubuntu17.10 Install Docker-ce
官网目前的安装步骤在最新版本的Ubuntu17.10 上会提示没有安装源,下面是针对17.10 安装步骤: 参考资料 sudo apt-get update sudo apt-get install ...
- 【Mac + Appium + Python3.6学习(二)】之Android自动化测试,appium-desktop配置和简易自动化测试脚本
上一篇文章介绍安装appium测试环境,这一片研究介绍如何测试Android自动化. 上一篇地址:<[Mac + Appium学习(一)]之安装Appium环境> 这一篇参考:<Ma ...
- ThinkPHP与EasyUI整合之三(searchbox):在datagrid中查询指定记录
在datagrid中toolbar添加searchbox查询框,根据列范围查询数据,先看效果图: 1. searchbox采用easyui的Demo例子,再加以js扩展,根据datagrid中的列数据 ...
- printf,sprintf,vsprintf
printf,sprintf比较常用,vsprintf不常用. 1. 三个函数的声明: int printf (const char * szFormat, ...); int sprintf (ch ...
- lumen 事件
今天需要实现日志功能,所有使用了一下lumen的event(事件)和listener(监听) Lumen事件:https://lumen.laravel-china.org/docs/5.3/even ...
- spring无法启动常见原因及排查方法
这里总结的问题,通常啥错误也不报,需要自个debug排查,当然每个人遇到的问题可能是不同的,这里仅仅是我个人帮同事解决问题后的一些总结,可能网上的小伙伴可能也遇到,姑且简单记录一下: 1. mybat ...
- Python 基础爬虫架构
基础爬虫框架主要包括五大模块,分别为爬虫调度器.url管理器.HTML下载器.HTML解析器.数据存储器. 1:爬虫调度器主要负责统筹其他四个模块的协调工作 2: URL管理器负责管理URL连接,维护 ...
- docker学习笔记(1)概述、原理学习、常用命令
一.Docker概述 Docker是基于Go语言实现的云开源项目,诞生于2013年初,目前主流的Linux操作系统已支持Docker,如Redhat RHEL6.5/CentOS6.5.Ubuntu ...