Codeforces Round #444(div2) ABC

A.Div. 64

Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.

Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system.

Input

In the only line given a non-empty binary string s with length up to 100.

Output

Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.

Examples

Input
100010001
Output
yes
Input
100
Output
no

Note

In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.

You can read more about binary numeral system representation here: https://en.wikipedia.org/wiki/Binary_system

题意:给出一个二进制串,然后可以删除任意个数,求最后·二进制换为十进制能整除64

直接判断末尾0个数>=6就行

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 100000+5;
int main()
{
    string a;
    int sum=0;
    bool fg=0;
    cin>>a;
    int len=a.size();
    if(len<7)
    {
        printf("no\n");
        return 0;
    }
    for(int i=len-1; i>=0; i--)
    {
        if(a[i]=='0') sum++;
        if(a[i]=='1'&&sum>=6)
        {
            fg=1;
            break;
        }
    }
    if(fg) printf("yes\n");
    else printf("no\n");
}
View Code

B.Cubes for Masha

Absent-minded Masha got set of n cubes for her birthday.

At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.

To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.

The number can't contain leading zeros. It's not required to use all cubes to build a number.

Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.

Input

In first line integer n is given (1 ≤ n ≤ 3) — the number of cubes, Masha got for her birthday.

Each of next n lines contains 6 integers aij (0 ≤ aij ≤ 9) — number on j-th face of i-th cube.

Output

Print single integer — maximum number x such Masha can make any integers from 1 to x using her cubes or 0 if Masha can't make even 1.

Examples

Input
3
0 1 2 3 4 5
6 7 8 9 0 1
2 3 4 5 6 7
Output
87
Input
3
0 1 3 5 6 8
1 2 4 5 7 8
2 3 4 6 7 9
Output
98

Note

In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.

题意:n个魔方,每个面有一个数字(0~9),,然后选择1~n个魔方的一个面排列,求最大组成的x(1~x都能组成) 。如果三个面分别为1 2 3这样顺序排列 那么值就是123。

思路:因为最多3个魔方,能组成的值不会大于99.。因为你会发现要组成99你需要(11,22,33,44,55,66,77,88,99,)这个一共18个数字,也就是3*6 所有面都用上了,且最大值为99,不可能出现三位数。所以,我们只需要求任意两个面组合就行。我们使用一个vis数组记录,最后遍历vis数组,当vis[i]为0时 输出i-1即可。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[3][6];
bool vis[100];
int main()
{
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 6; j++)
        {
            scanf("%d",&a[i][j]);
            vis[a[i][j]]=1;
        }
    }
    for(int i=0; i<n; i++)
        for(int j=0; j<6; j++)
        {
            for(int k=0; k<n; k++)
            {
                if(i==k)
                    continue;
                for(int p=0; p<6; p++)
                {
                    vis[a[i][j]*10+a[k][p]]=1;
                }
            }
        }
        for(int i=1;i<=99;i++)
        {

            if(!vis[i])
            {
                printf("%d\n",i-1);
                return 0;
            }
        }

}
View Code

C.Solution for Cub

During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.

It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.

To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.

Cube is called solved if for each face of cube all squares on it has the same color.

https://en.wikipedia.org/wiki/Rubik's_Cube

Input

In first line given a sequence of 24 integers ai (1 ≤ ai ≤ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.

Output

Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.

Examples

Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Output
YES

Note

In first test case cube looks like this:

In second test case cube looks like this:

It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.

题意:一个魔方,输入24个块的颜色,然后扭一次,使得魔方变成6个面颜色一样。

思路:直接判断6次扭就行,每次扭一个面,可以扭四次,但是有两次重复,实际一共只有6种方法,大家可以自己YY一下

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[25];
bool check(int i,int j,int k,int p)
{
    if(a[i]==a[j]&&a[j]==a[k]&&a[k]==a[p])
        return true;
    return false;
}
int main()
{
    for(int i=1;i<=24;i++)
        scanf("%d",&a[i]);
    if(check(1,3,6,8)&&check(5,7,10,12)&&check(2,4,22,24)&&check(9,11,21,23))
        puts("YES");
    else
        if(check(6,8,9,11)&&check(2,4,5,7)&&check(21,23,1,3)&&check(10,12,22,24))
        puts("YES");
    else
        if(check(13,14,7,8)&&check(5,6,19,20)&&check(17,18,23,24)&&check(21,22,15,16))
        puts("YES");
    else
        if(check(5,6,15,16)&&check(7,8,17,18)&&check(21,22,19,20)&&check(13,14,23,24))
            puts("YES");
    else
        if(check(9,10,13,15)&&check(14,16,1,2)&&check(3,4,18,20)&&check(17,19,11,12))
        puts("YES");
    else
        if(check(9,10,18,20)&&check(17,19,1,2)&&check(3,4,13,15)&&check(14,16,11,12))
        puts("YES");
    else
        puts("NO");
}
View Code

后面的题,等实力提上来再去补吧

PS:摸鱼怪的博客分享,欢迎感谢各路大牛的指点~

PS:摸鱼怪的博客分享,欢迎感谢各路大牛的指点~

猜你喜欢

转载自www.cnblogs.com/MengX/p/9119531.html