题目链接:点击打开链接
A. Lesha and array splitting
time limit per test
memory limit per test
input
output
A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array A.
Lesha is tired now so he asked you to split the array. Help Lesha!
Input
n (1 ≤ n ≤ 100) — the number of elements in the array A.
n integers a1, a2, ..., an (3 ≤ ai ≤ 103) — the elements of the array A.
Output
A and satisfy all the constraints, print single line containing "NO" (without quotes).
YES" (without quotes). In the next line print single integer k — the number of new arrays. In each of the next k lines print two integers li and ri which denote the subarray A[li... ri] of the initial array A being the i-th new array. Integers li, rishould satisfy the following conditions:
- l1
- rk=n
- ri+ 1 =li+ 1 for each 1 ≤i<k.
If there are multiple answers, print any of them.
Examples
input
3 1 2 -3
output
YES 2 1 2 3 3
input
8 9 -12 3 4 -4 -10 7 3
output
YES 2 1 2 3 8
input
1 0
output
NO
input
4 1 2 3 -5
output
YES 4 1 1 2 2 3 3 4 4
大意:给你一个数组,问是否能找到元素和不为 0 的子数组。
思路:只要原数组不全为 0 就肯定 YES 啊,然后不为 0 的元素自己就是一个(只存在一个元素)数组,碰到 0 的元素,就跟下一个不为的 0 的元素合一块作为一个数组就行了
题目链接:
点击打开链接
B. Ilya and tic-tac-toe game
time limit per test
memory limit per test
input
output
4 × 4
4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other
Input
The tic-tac-toe position is given in four lines.
.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
input
xx.. .oo. x... oox.
output
YES
input
x.ox ox.. x.o. oo.x
output
NO
input
x..x ..oo o... x.xo
output
YES
input
o.x. o... .x.. ooxx
output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
大意:给你一个 4X4 的方格,两个人下棋,三个棋子连起来(横的,竖的,斜的)就获胜。现在该 llya 下棋了,问他落下一个棋子是否能获胜。
思路:出现可能的情况也不是很多,枚举每一种情况判断即可