For n edges, look for three edges, make it a triangle, and make the triangle the largest perimeter.

Source: Internet
Author: User

Analysis: Water problem, first of all the side of the sort, and then only need to determine whether the adjacent three edges can form a triangle, if possible, then the current triangle is all the circumference of the triangle before the largest, scan once sorted results can be the final answer.

#include <iostream> #include <algorithm>using namespace Std;int a[10005];int main () {int N,i,len,tmp;while ( Cin>>n && N) {len=0;for (i=0;i<n;i++) cin>>a[i];sort (a,a+n); Len=0;for (i=0;i+2<n;i++) if (a[ I]+a[i+1]>a[i+2]) {tmp=a[i]+a[i+1]+a[i+2];len=len>tmp?len:tmp;} Cout<<len<<endl;}    return 0;}


For n edges, look for three edges, make it a triangle, and make the triangle the largest perimeter.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.