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.

思路:

暴力模拟,一个数字里面每个骰子有且至多能用一次

 #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int weishu(int num) {
if(num>=&&num<=) return ;
if(num>=&&num<=) return ;
if(num>=&&num<=) return ;
return ;
}
bool exist(int ans[][], int rec[], int len) {
if(len==) {
int a=rec[];
if(ans[][a]||ans[][a]||ans[][a]) return true;
} else if(len==) {
int a=rec[],b=rec[];
if((ans[][a]&&ans[][b])
||(ans[][a]&&ans[][b])
||(ans[][a]&&ans[][b])
||(ans[][a]&&ans[][b])
||(ans[][a]&&ans[][b])
||(ans[][a]&&ans[][b]))
return true;
} else if(len==) {
int a=rec[],b=rec[],c=rec[];
if((ans[][a]&&ans[][b]&&ans[][c])
||(ans[][a]&&ans[][b]&&ans[][c])
||(ans[][a]&&ans[][b]&&ans[][c])
||(ans[][a]&&ans[][b]&&ans[][c])
||(ans[][a]&&ans[][b]&&ans[][c])
||(ans[][a]&&ans[][b]&&ans[][c]))
return true;
}
return false;
}
int main(){
int ans[][],n,num,bns[][],rec[];
memset(ans,,sizeof(ans));
/*read*/
scanf("%d",&n);
for(int i=;i<=n;++i) {
int flag[]={};
for(int j=;j<;++j) {
scanf("%d",&num);
if(flag[num]==) {
ans[i][num]++;
flag[num]=;
}
}
}
/*slove*/
int result=;
for(int i=;i<=;++i) {
if(i==) {
result=;
break;
}
int len=weishu(i);
int temp=i;
memcpy(bns,ans,sizeof(ans));
memset(rec,-,sizeof(rec));
for(int j=;j<=len;++j) {
int r=i%;
rec[j]=r;
i=i/;
}
i=temp;
if(!exist(ans,rec,len)) {
result=i-;
break;
}
}
printf("%d\n",result);
return ;
}

优化暴力模拟,不可能出现比99大的数字,因为如果要出现比99大的数字,那么需要有1 1,2 2,3 3,4 4,5 5,6 6,7 7,8 8,9 9这样的话已经有18个数字,即使三个骰子也只是刚好18个数字。其中必不可少的是数字0,加上就是19。所以不可能出现比99大的数字。

 #include <bits/stdc++.h>
using namespace std;
int main() {
int n,ans[][],vis[];
memset(vis,,sizeof(vis));
scanf("%d",&n);
for(int i=;i<=n;++i) {
for(int j=;j<=;++j) {
scanf("%d",&ans[i][j]);
}
}
for(int i=;i<=n;++i) {
for(int j=;j<=;++j) {
vis[ans[i][j]]=;
for(int k=;k<=n;++k) {
if(k==i) continue;
for(int l=;l<=;++l) {
vis[ans[i][j]*+ans[k][l]]=;
}
}
}
}
for(int i=;i<=;++i) {
if(!vis[i]) {
printf("%d\n",i-);
break;
}
}
return ;
}

codeforces 887B Cubes for Masha 两种暴力的更多相关文章

  1. codeforces 792CDivide by Three(两种方法:模拟、动态规划

    传送门:https://codeforces.com/problemset/problem/792/C 题意:给你一个字符串,要求让你删除最少个数的元素,使得最终答案是没有前导0并且是3的倍数. 题解 ...

  2. Codeforces Round #466 (Div. 2) B. Our Tanya is Crying Out Loud[将n变为1,有两种方式,求最小花费/贪心]

    B. Our Tanya is Crying Out Loud time limit per test 1 second memory limit per test 256 megabytes inp ...

  3. Codeforces Beta Round #13 E. Holes 分块暴力

    E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...

  4. Sql Server 聚集索引扫描 Scan Direction的两种方式------FORWARD 和 BACKWARD

    最近发现一个分页查询存储过程中的的一个SQL语句,当聚集索引列的排序方式不同的时候,效率差别达到数十倍,让我感到非常吃惊 由此引发出来分页查询的情况下对大表做Clustered Scan的时候, 不同 ...

  5. Codeforces Round #369 (Div. 2) A B 暴力 模拟

    A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #329 (Div. 2) A. 2Char 暴力

    A. 2Char Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/A De ...

  7. linux尝试登录失败后锁定用户账户的两种方法

    linux尝试登录失败后锁定用户账户的两种方法 更新时间:2017年06月23日 08:44:31   作者:Carey    我要评论   这篇文章主要给大家分享了linux尝试登录失败后锁定用户账 ...

  8. 寒假集训——搜索 D - Cubes for Masha

    #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h&g ...

  9. ZOJ-1610 线段树+两种查询方法(弥补我线段树区间填充的短板)

    ZOJ-1610 线段树+两种查询方法(弥补我线段树区间填充的短板) 题意 题意:给一个n,代表n次操作,接下来每次操作表示把[l,r]区间的线段涂成k的颜色其中,l,r,k的范围都是0到8000 这 ...

随机推荐

  1. Docker 如何支持多种日志方案?- 每天5分钟玩转 Docker 容器技术(88)

    将容器日志发送到 STDOUT 和 STDERR 是 Docker 的默认日志行为.实际上,Docker 提供了多种日志机制帮助用户从运行的容器中提取日志信息.这些机制被称作 logging driv ...

  2. linux学习(十一)用户和用户组管理

    一.用户文件 文件:/etc/passwd 这个文件记录了用户了用户名,用户id,所属组,家目录,shell信息: [root@iZ25lzba47vZ ~]# tail -n3 /etc/passw ...

  3. J - Scarily interesting! URAL - 2021

    This year at Monsters University it is decided to arrange Scare Games. At the Games all campus gathe ...

  4. poj 3340 Barbara Bennett's Wild Numbers(数位DP)

    Barbara Bennett's Wild Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3153   A ...

  5. 脑残手贱:被NFS祸害的调度系统

    建议:任何时候,都要三思而后行!!! 事请的缘由 系统中采用slurm调度系统来进行并行计算.但是在GPU节点上,无论如何都无法启动slurmd,报插件初始化错误的故障. 因此需要编译新的munge和 ...

  6. 三目运算的使用&bytes类型转str类型

    一.三目运算的使用 就像c语言中有三目运算符一样,python中也有三目运算符,废话不多说直接上代码 a=3 c=4 b=a if a>c else c print(b) 意思就和 if a&g ...

  7. .Net 上传图片之前获取图片的宽高

    Stream st = Request.Files[0].InputStream;                  Byte[] buffer = new Byte[st.Length];      ...

  8. Chartist.js-同时画柱状图和折线图

    最近几天都在研究chartist,因为echarts生成的图是位图,导成PDF的时候不够清晰.而chartist是搜到的免费插件中呼声较高的,基于SVG. 今天主要是想举一些代码例子给大家,介绍下如何 ...

  9. 谈一次java web系统的重构思路

    ——略谈Java web软件如何提供二次开发接口 接手公司的一个Java web软件产品,该软件采用传统的dwr框架.dwr框架相当于一个中间层,使得javascript能够识别Java类对象,进而能 ...

  10. ThinkPHP模版验证要注意的地方

    Model页面 <?php class LoginModel extends Model { //protected $tableName = 'userinfo'; //表名和model不一致 ...