#261. 检查数组中的271模式

    ID: 261 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatWarmup-2gesp1循环结构条件结构

检查数组中的271模式

Check 271 Pattern

Background

Dawei is studying a special number sequence. He wants to know if a specific pattern exists in an integer array.

Problem Description

Given an array of integers, return true if it contains a 2,7,12, 7, 1 pattern. A 2,7,12, 7, 1 pattern refers to a value, followed by the value plus 55, followed by the value minus 11. Additionally, the 2,7,12, 7, 1 pattern counts even if the third value differs by 22 or less from the correct value (value minus 11). For example, if the first value is xx, the second is x+5x+5, and the third is zz, then a 2,7,12, 7, 1 pattern exists if z(x1)2|z - (x-1)| \le 2.

Input Format

Input is given from standard input in the following format.

A single line containing several integers, separated by spaces.

Output Format

Output is printed to standard output in the following format.

Output true if a 2,7,12, 7, 1 pattern exists in the array; otherwise, output false.

Sample

1 2 7 1
true
1 2 8 1
false
2 7 1
true

Sample Explanation

  • Sample 1: Array [1 2 7 1]. When x=2x=2, the second element is 2+5=72+5=7, and the third element is 11. Since 1(21)=11=02|1 - (2-1)| = |1-1| = 0 \le 2, a 2,7,12, 7, 1 pattern exists.
  • Sample 2: Array [1 2 8 1]. When x=2x=2, the second element is 88, which is not equal to 2+5=72+5=7. Therefore, no 2,7,12, 7, 1 pattern exists.
  • Sample 3: Array [2 7 1]. When x=2x=2, the second element is 2+5=72+5=7, and the third element is 11. Since 1(21)=11=02|1 - (2-1)| = |1-1| = 0 \le 2, a 2,7,12, 7, 1 pattern exists.

Constraints

Time limit for each test case is 11 second, and memory limit is 10241024 KiB.