Codeforces Round #444 (Div. 2) A-C 题解

A. Div. 64
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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


打cf真的是一个不断学习的过程,题目问要求去掉几个数之后剩下的数能整除64.
此题要注意有前导0,64的二进制是(1000000),所以搜到第一个1开始,后面的0只要大于等于6个就ok。
代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
string map;

int main()
{
	int n,i,j,k;
	cin>>map;
	for(i=0;i<map.length();i++)
	{
		if(map[i]=='1')
		break;
	}
	int ans=0;
	for(j=i;j<map.length();j++)
	{
		if(map[j]=='0')
		ans++;
	}
	if(ans>=6)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

B. Cubes for Masha
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.


好狠毒的一个题,无限WA,就是n组6个数,问从1开始最多能组到多大,要求从1到这个数都存在。
就是模拟啊,然后需要注意的是:这个数最大不超过99,因为如果到了99,需要2个1,2个2……2个9,此时就已经18个数了,所以模拟一下就ok。
代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
int vis[100];
int map[10][10];

int main()
{
	int n,i,j,k,l;
	while(cin>>n)
	{
		mset(vis,0);
		for(i=0;i<n;i++)
		{
			for(j=0;j<6;j++)
			{
				cin>>map[i][j];
				vis[map[i][j]]=1;
			}
		}
		for(i=0;i<n;i++)
		{
			for(j=0;j<6;j++)
			{
				for(k=0;k<n;k++)
				{
					if(i==k)
					continue;
					for(l=0;l<6;l++)
					{
						vis[map[i][j]*10+map[k][l]]=1;
					}
				}
			}
		}
		for(i=1;i<=99;i++)
		{
			if(!vis[i])
			break;
		}
		cout<<i-1<<endl;
	}
	return 0;
}

C. Solution for Cube
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

传送门: 点击打开链接

代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
int map[30][30],vis[30];

int main()
{
	int i,j,k,x,ans=0;
	for(i=0;i<6;i++)
	{
		set <int> s;
		for(j=0;j<4;j++)
		{
			cin>>x;
			s.insert(x);
		}
		if(s.size()==1)
		ans++;
		else if(s.size()==2)
		{
			int pre=-1,pre1=-1;
			for(auto it: s)
			{
				if(pre==-1)
				pre=it;
				else
				pre1=it;
			}
			if(pre>pre1)
			swap(pre,pre1);
			map[pre][pre1]++;
		}
		else
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	if(ans==2)
	{
		for(i=1;i<=6;i++)
		{
			for(j=1;j<=6;j++)
			{
				if(map[i][j]>=2)
				{
					cout<<"NO"<<endl;
					return 0;
				}
			}
		}
		cout<<"YES"<<endl;
	}
	else
	cout<<"NO"<<endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值