Fourth week of training (efficient algorithm design) m problem (scanning method)

Source: Internet
Author: User

Original title: UVA11078

Test instructions: Give you an array, set a[], ask for a m=a[i]-a[j],m bigger the better, and I must be less than J

How can I ask? Sort? Requirement I is less than J. Enumeration? Can only say time-out no limit. So iterate over the array, set the first to be a "0", then meet the number of a "0" to update it, and then take this to the meiosis group of each element, but also to constantly update the M value.

#include"Iostream"#include"Set"#include"CString"#include"Cstdio"#include"Algorithm"UsingNamespace Std;Constint MAXN=100000+10;int a[MAXN];IntMain(){int T; Cin>>t;While(T--){int n; Cin>>n;For(int I=0; I<n; I++){cin>>a[I];}int x=a[0];int ans=-1;For(int I=1;i<n;i< Span class= "Sh-symbol" >++) {ans=max< Span class= "Sh-symbol" > (X-a[i],ans=max (A[i< Span class= "Sh-symbol" >],x);  Cout<<ans<<endl return 0;< Span class= "Sh-cbracket" >             

Fourth week of training (efficient algorithm design) m problem (scanning method)

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.