1. 程式人生 > >B. Mahmoud and a Triangle-水水的-codeforce

B. Mahmoud and a Triangle-水水的-codeforce

本來我都不想寫這一道題了,結果一查,題解還那麼多。如果還是比較有趣的。。
給定一個數n,然後給你n個數,問這些數是否能構成三角形。
原文給的是 這個單詞。A non-degenerate triangle,不退化的三角形,後經必應發現 不退化三角形就是
退化三角形是指面積為零的三角形。滿足下列條件之一的三角形即可稱為退化三角形:三個內角的度數為 (180°,0°,0°) 或 (90°,90°,0°);三邊其中一條邊的長度為0;一條邊的長度等於另外兩條之和。有人認為退化三角形並不能算是三角形,這是由於它介乎於三角不等式之間,在一些資料中已否定了其中一條邊等於其餘兩條邊之和的情況。
一句話,退化三角形就不是三角形。。。
所以原題就是看是否可以找三條邊構成三角形,,,

還有一個要了解的地方,我開始用的迴圈遍歷,後來發現一個道理,
我們只需要對相鄰的邊進行遍歷就可以了,因為相鄰排序為
a,b,c,d,e,f,g;
如果a+b

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=100005;
int main()
{   int a[maxn];
    int n;
     scanf("%d",&n);
     for(int i=1;i<=n;i++)
     {   scanf
("%d",&a[i]); } sort(a+1,a+n+1); for(int i=1;i<=n-2;i++) { if(a[i]+a[i+1]>a[i+2]&&a[i+2]-a[i]<a[i+1]) {printf("YES\n"); return 0; } } printf("NO\n"); return 0; }

相關推薦

B. Mahmoud and a Triangle-的-codeforce

本來我都不想寫這一道題了,結果一查,題解還那麼多。如果還是比較有趣的。。 給定一個數n,然後給你n個數,問這些數是否能構成三角形。 原文給的是 這個單詞。A non-degenerate trian

Mahmoud and a Triangle (CodeForces - 766B) 思維

Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate t

CodeForces 817 B.Makes And The Product(~)

Description 給出n個正整數ai,問有多少三元組(i,j,k)滿足1≤i<j<k≤n且ai⋅aj⋅ak最小 Input 第一行一整數n表示序列長度,之後輸入n個整數ai(3≤

codeforces 862B B. Mahmoud and Ehab and the bipartiteness

com set pac 並且 復雜 oid include ces http http://codeforces.com/problemset/problem/862/B 題意: 給出一個有n個點的二分圖和n-1條邊,問現在最多可以添加多少條邊使得這個圖中不存在自環,重邊,

B. Alyona and a tree

++ pre == color span include printf print while 二分+dfs序+前綴和+瞎幾把yy #include "a.h" int n; aLL a; struct edge { int to, nx, w

#DFS序+二分+字首和# Codeforces Round #381 (Div. 1) B. Alyona and a tree

題目連結 B. Alyona and a tree time limit per test  2 seconds memory limit per test  256 megabytes input  standard input output&

E. Mahmoud and a xor trip 按位處理 異或 dp

Description Mahmoud and Ehab live in a country with n cities numbered from 1 to n and connected by n - 1 und

Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 字首和

  B. Alyona and a tree 題目連線: http://codeforces.com/contest/739/problem/B Description Alyona has a tree with n vertices. The root of the

codeforces#766 D. Mahmoud and a Dictionary (並查集)

namespace define scanf 對應關系 force sha ict codeforce sharp 題意:給出n個單詞,m條關系,q個詢問,每個對應關系有,a和b是同義詞,a和b是反義詞,如果對應關系無法成立就輸出no,並且忽視這個關系,如果可以成立則加入這

codeforces#766 D. Mahmoud and a Dictionary (並查集)

題意:給出n個單詞,m條關係,q個詢問,每個對應關係有,a和b是同義詞,a和b是反義詞,如果對應關係無法成立就輸出no,並且忽視這個關係,如果可以成立則加入這個約束,並且輸出yes。每次詢問兩個單詞的關係,1,同義詞,2,反義詞,3,不確定 題解:這題思路比較奇特,開闢2*n的並查集的空間,第i+n代表i的

Mahmoud and a Dictionary CodeForces - 766D

Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i.&nbs

Hello 2019 B. Petr and a Combination Lock

兩個月以來,焦頭爛額的各種事把我煩的夠嗆,cf幾乎一點都沒打,水平下降得很厲害。 這個題主要學習一個演算法,二進位制數取位數,之後判斷奇偶性,來遍歷整個陣列或某些其他容器。 for (int i=0;i<(1<<n);i++) { int sum=0;

CF821 A. Okabe and Future Gadget Laboratory

push nbsp int 個數 return bar .com tin link Link 題意:詢問n X n中非1數是否能夠由同行同列中分別取兩個數做和得到。 思路:水題。 /** @Date : 2017-07-03 16:23:18 * @

HDU-2033-人見人愛A+B

HDOJ上面已經有10來道A+B的題目了,相信這些題目曾經是大家的最愛,希望今天的這個A+B能給大家帶來好運,也希望這個題目能喚起大家對ACM曾經的熱愛。 這個題目的A和B不是簡單的整數,而是兩個時間,A和B 都是由3個整陣列成,分別表示時分秒,比如,假設A為34 45 56

【Codeforces Round 332 (Div 2)A】【題】A. Patrick and Shopping 遍歷三元環的最小成本

Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his hous

codeforces 508 B Anton and currency you all know(

Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations

HDU 6182 A Math Problem

std 水題 div 輸出 iterator code php else fin   題目鏈接: http://acm.hdu.edu.cn/showproblem.php?pid=6182   題目描述: 輸入N, 輸出滿足k^k <= N 的 k的個數   解題思

Codeforces Round #396(Div. 2) A. Mahmoud and Longest Uncommon Subsequence

color HA \n seq 字符 turn ces DC %s 【題意概述】   找兩個字符串的最長不公共子串。 【題目分析】   兩個字符串的最長不公共子串就應該是其中一個字符串本身,那麽判斷兩個字符串是否相等,如果相等,那麽肯定沒有公共子串,輸出“-1”.否則就

B - Average Numbers CodeForces - 134A(題,思維)

You are given a sequence of positive integers a1, a2, …, an. Find all such indices i, that the i-th element equals the arithmetic mean of all othe

Newcoder 109 A.長方體(~)

Description 給出共享長方體一個頂點的三個面的面積,求它十二條邊的邊長和。 Input 一行三個整數 a ,