2-11 integer Array A1

Source: Internet
Author: User


Analysis of the problem, only to determine whether there are Ai = i in an array of integers, you can instead judge the linear array of integers, and (Ai = i is an over the origin of a line with a slope of 1) whether there is a point of intersection.

The presence of intersections has the following conditions

1, the slope of the integer array equals 1: or repeat or no intersection

2, the slope of the integer array is greater than 1: only if the smallest point of the integer array, located below the AI = I line, the maximum point of the integer array, is located in the AI = I this line above, there may be intersection

3, the slope of the integer array is less than 1: only if the smallest point of the integer array, located above the AI = I line, the maximum point of the integer array, is located in the AI = i this line below, there may be intersection

So:

if (A1 < 1)

{

if (a > N) return True;

else return False;

}

else if (A1 = = 1) return True;

Else

{

if (a < n) return ture;

else return False;

}

}


The problem is deduced: Finding the intersection point I.

First, if there is a intersection, when there is a point of intersection, use the binary method to find the intersection.


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.