Codeforces Round #390 (Div. 2)(A+B)

来源:互联网 发布:asp网络程序怎么样? 编辑:程序博客网 时间:2024/05/16 12:17

A. Lesha and array splitting

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

One spring day on his way to university Lesha found an array 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

The first line contains single integer n (1 ≤ n ≤ 100) — the number of elements in the array A.

The next line contains n integers a1, a2, …, an ( - 103 ≤ ai ≤ 103) — the elements of the array A.

Output

If it is not possible to split the array A and satisfy all the constraints, print single line containing “NO” (without quotes).

Otherwise in the first line print “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, ri should satisfy the following conditions:
• l1 = 1
• 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
题意:给出一个长度为N的数组,让你拆分成若干个子区间,使得每个子区间的和不为0.有解输出任意可行解,无解输出NO。
题解:只要数组不全为0,就有解。注意末尾有0的情况。

#include <bits/stdc++.h>#define bababaa printf("!!!!!!!\n")using namespace std;int a[200];int al[200];int ar[200];int n;int main(){    cin>>n;    int sum=0;    for(int i=1;i<=n;i++)    {        cin>>a[i];        if(a[i]!=0)            sum++;    }    if(sum==0)    {        cout<<"NO"<<endl;    }    else    {        cout<<"YES"<<endl;        int tmp=0;        for(int i=1;i<=n;i++)        {            al[++tmp]=i;            while(a[i]==0) i++;            if(--sum==0) break;            ar[tmp]=i;        }        ar[tmp]=n;        cout<<tmp<<endl;        for(int i=1;i<=tmp;i++)        {            cout<<al[i]<<" "<<ar[i]<<endl;        }    }}

B. Ilya and tic-tac-toe game

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn’t finish the last game. It was Ilya’s turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.

The rules of tic-tac-toe on the 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 (horizontal, vertical or diagonal).

Input

The tic-tac-toe position is given in four lines.

Each of these lines contains four characters. Each character is ‘.’ (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

Print single line: “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.
题意:问X再落一子后,能否获胜(获胜满足有一个三个相连)
题解;一个简单的搜索。。。
代码:

#include <bits/stdc++.h>#define bababaa printf("!!!!!!!\n")using namespace std;char a[10][10];int b[10][10];bool flag=false;void dfs(int x,int y){    if(x+2>=1&&x+2<=4)    {        if(b[x][y]+b[x+1][y]+b[x+2][y]==2)            flag=true;    }    if(y+2>=1&&y+2<=4)    {        if(b[x][y]+b[x][y+1]+b[x][y+2]==2)            flag=true;    }    if(x+2>=1&&x+2<=4&&y+2>=1&&y+2<=4)    {        if(b[x][y]+b[x+1][y+1]+b[x+2][y+2]==2)            flag=true;    }    if(x+2>=1&&x+2<=4&&y-2>=1&&y-2<=4)    {        if(b[x][y]+b[x+1][y-1]+b[x+2][y-2]==2)            flag=true;    }}int main(){    for(int i=1;i<=4;i++)        scanf("%s",a[i]+1);        for(int i=1;i<=4;i++)        {            for(int j=1;j<=4;j++)            {                if(a[i][j]=='x')                    b[i][j]=1;                else if(a[i][j]=='o')                    b[i][j]=-100;                else                    b[i][j]=0;            }        }        for(int i=1;i<=4;i++)        {            for(int j=1;j<=4;j++)            {                    dfs(i,j);                    if(flag) break;            }            if(flag) break;        }        if(flag)            cout<<"YES"<<endl;        else            cout<<"NO"<<endl;}
0 0
原创粉丝点击