Timus 1010. discrete function

Source: Internet
Author: User
Timus 1010. The discrete function requires that the given discrete function be used to locate the greatest dip in the line of the corresponding point in the Cartesian coordinate system.
1010. discrete function

Time Limit: 1.0 second
Memory limit: 16 MB

There is a discrete function. It is specified for integer arguments from 1 N(2 ≤ N
≤ 100000). Each value of the function is longint (signed long in C ++ ).
You have to find such two points of the function for which all points
Between them are below than straight line connecting them and
Inclination of this straight line is the largest. inputthere is NIn the first line. NLines follow with the values of the function for the arguments 1, 2 ,..., NRespectively. outputa
Pair of integers, which are abscissas of the desired points, shocould be
Written into one line of output. The first number must be less then
Second one. If it is any ambiguity your program shocould write the pair
With the smallest first number. Sample
Input Output
3
2
6
4
1 2

Problem Source:Third open ustu Collegiate Programming Contest (phystech cup), March 18,200 0

The answer is as follows:

1 using system;
2
3 namespace skyiv. Ben. timus
4 {
5 // http://acm.timus.ru/problem.aspx? Space = 1 & num = 1010
6 Sealed class t1010
7 {
8 Static void main ()
9 {
10 int I0 = 0, n = int. parse (console. Readline ());
11 long R0 = 0, V1 = int. parse (console. Readline ());
12 For (INT I = 0; I <n-1; I ++)
13 {
14 long v2 = int. parse (console. Readline ());
15 long R = math. Abs (V1-V2 );
16 V1 = V2;
17 if (R0 <R)
18 {
19 R0 = R;
20 I0 = I;
21}
22}
23 console. writeline ("{0} {1}", I0 + 1, I0 + 2 );
24}
25}
26}

This is actually very simple, as long as you realize that the two endpoints of the line with the greatest inclination must be adjacent points.

The tangent value (TAN) of the dip of the two points is equal to the deviation of the ordinate values of the two points divided by the deviation of the abscissa. Because these two points are adjacent points, the deviation of the abscissa is 1, that is, directly equal to the deviation of the ordinate.

"Each value of the function is longint (signed long in C ++ ). ", that is, the value range of the discrete function is the signed long data type in C ++, which is actually equivalent to the INT (namely: system. int32) data type, value range:-2,147,483,648 to + 2,147,483,647. Therefore, you can use the Int. parse () method to read the input. However, you must use the long (system. int64) data type, which is equivalent to the signed long data type in C ++. The value range is-9,223,372,036,854,775,808 to + 9,223,372,036,854,775,807. Otherwise, the computing may overflow.

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.