Codeforces Round #444 (Div. 2)
来源:互联网 发布:video.js 播放flv 编辑:程序博客网 时间:2024/06/07 04:04
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.
题意分析:
给几个骰子,然后上面的六个面为0~9,所以最大就是999。写一个vis[1000]来记录连续的东东,如果连续的话,将vis[i]=1,然后再最后遍历的时候,当vis[i]!=1的时候输出i-1即为所求。
然后是分析一下这个过程。先循环找数,然后将它赋值为1后可以找它后面的数,也就说以a[i]为十位,从别的骰子中找个位啥的 - -
说的比较细,因为我水嘛!
代码贴下
#include <bits/stdc++.h>using namespace std;int main() { int n,ans[4][7],vis[1000]; memset(vis,0,sizeof(vis)); scanf("%d",&n); for(int i=1;i<=n;++i) { for(int j=1;j<=6;++j) { scanf("%d",&ans[i][j]); } } for(int i=1;i<=n;++i) { for(int j=1;j<=6;++j) { vis[ans[i][j]]=1; for(int k=1;k<=n;++k) { if(k==i) continue; for(int l=1;l<=6;++l) { vis[ans[i][j]*10+ans[k][l]]=1; } } } } for(int i=1;i<=999;++i) { if(!vis[i]) { printf("%d\n",i-1); break; } } return 0;}
- Codeforces Round #444 (Div. 2)
- Codeforces Round #444 (Div. 2)
- Codeforces Round #444 (Div. 2)
- Codeforces Round #444 (Div. 2) 总结
- Codeforces Round #444 (Div. 2) C
- Codeforces Round #444 (Div. 2)-ABC
- Codeforces Round #444 (Div. 2)A. Div. 64
- Codeforces Round #444 (Div. 2) A. Div. 64
- Codeforces Round #444(Div. 2) A. Div. 64
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- fiddler无法抓包
- NGUI UIButton 添加带参数事件
- golang sync WaitGroup
- 电子商务平台 b2b2c o2o java web 源码
- 微信企业号开发:添加修改通讯录
- Codeforces Round #444 (Div. 2)
- Java基础之循环
- 多个线程间共享数据的几种方式
- 什么是256位加密?
- JDBC笔记(六)DBUtils工具
- 解密蓝牙 mesh系列文章汇总
- build path
- Spark SQL案例介绍与编程实现
- Spring开发环境测试HelloWorld