题目链接:​​点击打开链接​

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 lirishould 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 的元素合一块作为一个数组就行了

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef pair<int,int> pii;
int n;
int a[110];
pii ans[110];
int main()
{
while(~scanf("%d",&n))
{
int cnt=0,k=0,p=1;
for(int i=1;i<=n;i++)
{
scanf("%d",a+i);
if(a[i]!=0)
{
ans[k].first=p;
ans[k++].second=i;
p=i+1;
}
}
if(p!=n+1) // 说明末尾有存在一定数量的 0
ans[k-1].second=n;
if(k==0)
{
puts("NO");
}
else
{
puts("YES");
printf("%d\n",k);
for(int i=0;i<k;i++)
printf("%d %d\n",ans[i].first,ans[i].second);
}
}
return 0;
}
/*

5
1 -1 1 -1 1

*/


题目链接:

​点击打开链接​

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 下棋了,问他落下一个棋子是否能获胜。


思路:出现可能的情况也不是很多,枚举每一种情况判断即可

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
char cell[10][10];
bool judge(int px,int py)
{
if(px>=0&&px<4&&py>=0&&py<4)
return 1;
return 0;
}
bool find(int px,int py,char ch)
{
if(judge(px+1,py)&&judge(px+2,py)) // 同一列
{
if(cell[px+1][py]==ch&&cell[px+2][py]==ch)
return 1;
}
if(judge(px-1,py)&&judge(px+1,py))
{
if(cell[px-1][py]==ch&&cell[px+1][py]==ch)
return 1;
}
if(judge(px-2,py)&&judge(px-1,py))
{
if(cell[px-2][py]==ch&&cell[px-1][py]==ch)
return 1;
}

if(judge(px,py+1)&&judge(px,py+2)) // 同一列
{
if(cell[px][py+1]==ch&&cell[px][py+2]==ch)
return 1;
}
if(judge(px,py-1)&&judge(px,py+1))
{
if(cell[px][py-1]==ch&&cell[px][py+1]==ch)
return 1;
}
if(judge(px,py-2)&&judge(px,py-1))
{
if(cell[px][py-2]==ch&&cell[px][py-1]==ch)
return 1;
}

if(judge(px+1,py+1)&&judge(px+2,py+2)) // 对角线(向右斜)
{
if(cell[px+1][py+1]==ch&&cell[px+2][py+2]==ch)
return 1;
}
if(judge(px-1,py-1)&&judge(px+1,py+1))
{
if(cell[px-1][py-1]==ch&&cell[px+1][py+1]==ch)
return 1;
}
if(judge(px-2,py-2)&&judge(px-1,py-1))
{
if(cell[px-2][py-2]==ch&&cell[px-1][py-1]==ch)
return 1;
}

if(judge(px-1,py+1)&&judge(px-2,py+2)) // 对角线(向左斜)
{
if(cell[px-1][py+1]==ch&&cell[px-2][py+2]==ch)
return 1;
}
if(judge(px+1,py-1)&&judge(px-1,py+1))
{
if(cell[px+1][py-1]==ch&&cell[px-1][py+1]==ch)
return 1;
}
if(judge(px+1,py-1)&&judge(px+2,py-2))
{
if(cell[px+1][py-1]==ch&&cell[px+2][py-2]==ch)
return 1;
}
return 0;
}
int main()
{
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
cin>>cell[i][j];
}
int num1=0,num2=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(cell[i][j]=='x')
num1++;
if(cell[i][j]=='o')
num2++;
}
}
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(cell[i][j]=='.')
{
if(num1>num2)
{
if(find(i,j,'o'))
{
puts("YES");
return 0;
}
}
else if(num1==num2)
{
if(find(i,j,'x'))
{
puts("YES");
return 0;
}
}
}
}
}
puts("NO");
return 0;
}