其他分享
首页 > 其他分享> > Traveling(AtCoder-3875)

Traveling(AtCoder-3875)

作者:互联网

Problem Description

AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0,0) at time 0, then for each i between 1 and N (inclusive), he will visit point (xi,yi) at time ti.

If AtCoDeer is at point (x,y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x−1,y), (x,y+1) and (x,y−1). Note that he cannot stay at his place. Determine whether he can carry out his plan.

Constraints

  • 1 ≤ N ≤ 105
  • 0 ≤ xi ≤ 105
  • 0 ≤ yi ≤ 105
  • 1 ≤ ti ≤ 105
  • ti < ti+1 (1 ≤ i ≤ N−1)
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N
t1 x1 y1
t2 x2 y2
:
tN xN yN

Output

If AtCoDeer can carry out his plan, print Yes; if he cannot, print No.

Example

Sample Input 1

2
3 1 2
6 1 1

Sample Output 1

Yes
For example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1), (1,0), then (1,1).

Sample Input 2

1
2 100 100

Sample Output 2

No
It is impossible to be at (100,100) two seconds after being at (0,0).

Sample Input 3

2
5 1 1
100 1 1

Sample Output 3

No

题意:给出一个 01 串,要求寻找一个最大长度 k,每次在 01 串中选取长度至少为 k 的区间,将区间内的值取反,通过若干次操作后,使得 01 串变为全 0 串,求这个最大长度 k

思路:

由于要求的是 k 的最大长度,因此无需考虑翻转次数,也就是说最后变成全 0 还是全 1 都不影响结果

对于第 i 个字符来说,假设其前 i-1 个字符相等,且其与前 i-1 个字符不等,即 s[1]=s[2]=...=s[i-1]≠s[i],那么为了最后变为一致的结果,那么一定会选择翻转前 i 个字符,或者翻转后 n-i 个字符

以 00010100 为例,前 3 个字符相同第 4 个字符与前三个不同,为了达到最终所有字符相同,要么翻转前 4 个变为 11100100 然后再进行翻转,要么翻转后 5 个变为 00001011 然后再进行翻转

因此可以去枚举字符串,寻找第 i-1 个字符与第 i 个字符不同的 i,在 i 和 n-i 中去取最大的一个就是每一个字符进行翻转的最大值,由于要求最大的长度 k,因此在每一个字符进行翻转的最大值中选最小的一个即可

Source Program

标签:AtCoder,3875,Sample,Traveling,Input,100,翻转,个字符,he
来源: https://blog.csdn.net/u011815404/article/details/95997851