#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 4e4 + 100;
int p[100][100];
int exa[maxn];
bool check(int a,int b,int c,int d,int f)
{
int y = p[0][a];
y = p[y][b];
y = p[y][c];
y = p[y][d];
if (p[y][f]==0) return 1;
return 0;
} int main()
{
for(int i=0;i<=9;i++)
{
for(int j=0;j<=9;j++)
{
scanf("%d", &p[i][j]);
}
}
for(int i=0;i<=9999;i++)
{
int a = i / 1000, b = (i / 100) % 10, c = (i / 10) % 10, d = i % 10;
int x = p[0][a];
x = p[x][b];
x = p[x][c];
x = p[x][d];
exa[i] = x;
}
ll ans = 0;
int flag = 0;
for(int i=0;i<=9999;i++)
{
flag = 0;
int a = i / 1000, b = (i / 100) % 10, c = (i / 10) % 10, d = i % 10;
if(a!=b&&check(b,a,c,d,exa[i]))
{
ans++;
continue;
}
if(b!=c&&check(a,c,b,d,exa[i]))
{
ans++;
continue;
}
if(c!=d&&check(a,b,d,c,exa[i]))
{
ans++;
continue;
}
if(d!=exa[i]&&check(a,b,c,exa[i],d))
{
ans++;
continue;
}
for(int j=0;j<=9;j++)
{
if (j == a) continue;
if (check(j,b,c,d,exa[i]))
{
// printf("2 ans=%d\n", ans);
ans++;
flag = 1;
break;
}
}
if (flag) continue;
for(int j=0;j<=9;j++)
{
if (j == b) continue;
if (check(a,j,c,d,exa[i]))
{
//printf("3 ans=%d\n", ans);
ans++;
flag = 1;
break;
}
}
if (flag) continue;
for(int j=0;j<=9;j++)
{
if (j == c) continue;
if (check(a,b,j,d,exa[i]))
{
//printf("4 ans=%d\n", ans);
ans++;
flag = 1;
break;
}
}
if (flag) continue;
for (int j = 0; j <= 9; j++)
{
if (j == d) continue;
if (check(a,b,c,j,exa[i]))
{
//printf("5 ans=%d\n", ans);
ans++;
flag = 1;
break;
}
}
if (flag) continue;
for(int j=0;j<=9;j++)
{
if (j == exa[i]) continue;
if(check(a,b,c,d,j))
{
//printf("6 ans=%d\n", ans);
ans++;
flag = 1;
break;
}
}
}
printf("%lld\n", ans);
return 0;
}

  

Description

The small city where you live plans to introduce a new social security number (SSN) system. Each citizen will be identified by a five-digit SSN. Its first four digits indicate the basic ID number (0000–9999) and the last one digit is a check digit for detecting errors. For computing check digits, the city has decided to use an operation table. An operation table is a 10 × 10 table of decimal digits whose diagonal elements are all 0. Below are two example operation tables.

 

Using an operation table, the check digit e for a four-digit basic ID number abcd is computed by using the following formula. Here, i ⊗ j denotes the table element at row i and column j.
e = (((0 ⊗ a) ⊗ b) ⊗ c) ⊗ d
For example, by using Operation Table 1 the check digit e for a basic ID number abcd = 2016
is computed in the following way.
e = (((0 ⊗ 2) ⊗ 0) ⊗ 1) ⊗ 6 = (( 1 ⊗ 0) ⊗ 1) ⊗ 6
= ( 7 ⊗ 1) ⊗ 6
= 9 ⊗ 6
= 6
Thus, the SSN is 20166.
Note that the check digit depends on the operation table used. With Operation Table 2, we have e = 3 for the same basic ID number 2016, and the whole SSN will be 20163

The purpose of adding the check digit is to detect human errors in writing/typing SSNs. The following check function can detect certain human errors. For a five-digit number abcde, the check function is defined as follows. check(abcde) = ((((0 ⊗ a) ⊗ b) ⊗ c) ⊗ d) ⊗ e
This function returns 0 for a correct SSN. This is because every diagonal element in an operation table is 0 and for a correct SSN we have e = (((0 ⊗ a) ⊗ b) ⊗ c) ⊗ d:
check(abcde) = ((((0 ⊗ a) ⊗ b) ⊗ c) ⊗ d) ⊗ e = e ⊗ e = 0.
On the other hand, a non-zero value returned by check indicates that the given number cannot be a correct SSN. Note that, depending on the operation table used, check function may return 0 for an incorrect SSN. Kinds of errors detected depends on the operation table used; the table decides the quality of error detection. The city authority wants to detect two kinds of common human errors on digit sequences: altering one single digit and transposing two adjacent digits, as shown in Figure B.1. An operation table is good if it can detect all the common errors of the two kinds on all SSNs made from four-digit basic ID numbers 0000–9999. Note that errors with the check digit, as well as with four basic ID digits, should be detected. For example, Operation Table 1 is good. Operation Table 2 is not good because, for 20613, which is a number obtained by transposing the 3rd and the 4th digits of a correct SSN 20163, check(20613) is 0. Actually, among 10000 basic ID numbers, Operation Table 2 cannot detect one or more common errors for as many as 3439 basic ID numbers. Given an operation table, decide how good it is by counting the number of basic ID numbers for which the given table cannot detect one or more common errors.

Input

The input consists of a single test case of the following format.
x00 x01 · · · x09
.
.
.
x90 x91 · · · x99
The input describes an operation table with xij being the decimal digit at row i and column j. Each line corresponds to a row of the table, in which elements are separated by a single space. The diagonal elements xii (i = 0, . . . , 9) are always 0

Output

Output the number of basic ID numbers for which the given table cannot detect one or more common human errors

Sample Input

0 3 1 7 5 9 8 6 4 2
7 0 9 2 1 5 4 8 6 3
4 2 0 6 8 7 1 3 5 9
1 7 5 0 9 8 3 4 2 6
6 1 2 3 0 4 5 9 7 8
3 6 7 4 2 0 9 5 8 1
5 8 6 9 7 2 0 1 3 4
8 9 4 5 3 6 2 0 1 7
9 4 3 8 6 1 7 2 0 5
2 5 8 1 4 3 6 7 9 0

Sample Output

0

Hint

这个题目把题意读懂了就好写了,比较简单,直接暴力就可以,不过有很多细节。

2292: Quality of Check Digits 中南多校 暴力枚举的更多相关文章

  1. 2293: Distribution Center 中南多校

    Description The factory of the Impractically Complicated Products Corporation has many manufacturing ...

  2. 中南多校对抗赛 第三场 E

    E:Eulerian Flight Tour 题意: 给你一张无向图,要你给这个图加边使得其形成一个欧拉回路 题解: 首先使得所有节点的度都为偶数,然后将这个图联通起来 对于度为奇数的点,将将他和他的 ...

  3. 中南多校对抗赛 第三场 B

    B:Arithmetic Progressions 题意: 给你一个长度为n的序列,问你这个序列中长度最长的等差数列长度为多少 题解: 方法一:将数组从小到大排序,n方扫,枚举出公差d,然后二分找有多 ...

  4. Highest Tower 18中南多校第一场H题

    一.题意 给出N个方块,要求给出一个方案,使得1. 所有方块都被使用到(题目数据保证这点) 2.所有方块垒成一个塔,且上面的方块宽度小于下面的方块 3.每个方块只能用一次,可以横着或者竖着. n范围5 ...

  5. Card Hand Sorting 18中南多校第一场C题

    一.题意 随机给你一堆牌(标准扑克牌),之后让你按照: 第一优先规则:所有相同花色的在一起 第二优先规则:所有相同花色的必须按照升序或者降序排列 问,你最少要拿出多少张牌插入到其他的地方以维持这个状况 ...

  6. Artwork 18年中南多校第一场A

    一.题意 对于一个矩阵,若干道命令,每道命令将会把某一段格子涂黑,请问每次涂黑之后矩阵中未被涂黑的块的数量? 二.思路 保存每道命令,并且忠实的执行他,到最后一步开始搜索联通块的数量,并将其保存. 之 ...

  7. 中南林业大学校赛 I 背包问题 ( 折半枚举 || 01背包递归写法 )

    题目链接 题意 : 中文题 分析 :  价值和重量都太过于大,所以采用折半枚举的方法,详细可以看挑战的超大背包问题 由于 n <= 30 那么可以不必直接记录状态来优化,面对每个用例 直接采用递 ...

  8. Codeforces Round #539 Div. 1

    A:即求长度为偶数的异或和为0的区间个数,对前缀异或和用桶记录即可. #include<iostream> #include<cstdio> #include<cmath ...

  9. CROC 2016 - Elimination Round (Rated Unofficial Edition) C. Enduring Exodus 二分

    C. Enduring Exodus 题目连接: http://www.codeforces.com/contest/655/problem/C Description In an attempt t ...

随机推荐

  1. C#实现放大镜

    winform实现一个跟随鼠标移动放大功能 实现步骤: 1.创建一个Form1,一个计时器timer1和一个图片显示控件pictureBox1 2.核心代码 ;//倍率,调节放大倍数,可由TrackB ...

  2. [PHP]代码执行和生命周期

    PHP代码的执行:1.和大部分程序一样,接收数据,处理数据,输出结果2.编写的代码就是输入的数据,php内核进行处理,返回相应的输出3.php作为业务程序和编译语言的区别就是,php多了一步把用户代码 ...

  3. [android] 绑定方式开启服务&调用服务的方法

    需求:后台开启一个唱歌服务,这个服务里面有个方法切换歌曲 新建一个SingService继承系统Service 重写onCreate()和onDestory()方法 填一个自定义的方法changeSi ...

  4. 我从Angular 2转向Vue.js, 也没有选择React

    译者按: 通过使用Angular的经历,作者已经完全转为Vue粉了!我们Fundebug目前还是用AngularJS 1,坦白说,学习曲线蛮陡的. 原文: Why we moved from Angu ...

  5. JavaScript 延迟加载

    默认情况下,浏览器是同步加载 JavaScript 脚本,即渲染引擎遇到<script>标签就会停下来,等到执行完脚本,再继续向下渲染.如果是外部脚本,还必须加入脚本下载的时间. 如果脚本 ...

  6. LeNet训练MNIST

    jupyter notebook: https://github.com/Penn000/NN/blob/master/notebook/LeNet/LeNet.ipynb LeNet训练MNIST ...

  7. js原型链结构与链表结构对比

    在结构上多一个指向自身的constructor构造函数,这就是原型链够简单吧. 利用原型链结构实现继承和向链表中插入节点,有区别吗? 没区别!!

  8. 2018-11-27 中文代码示例之Programming in Scala笔记第七八章

    续前文: 中文代码示例之Programming in Scala学习笔记第二三章 中文代码示例之Programming in Scala笔记第四五六章. 同样仅节选有意思的例程部分作演示之用. 源文档 ...

  9. https协议为什么比http协议更加安全

    一.http协议 http协议是一种网络传输协议,规定了浏览器和服务器之间的通信方式.位于网络模型中的应用层.(盗图小灰.ヾ(◍°∇°◍)ノ゙) 但是,它的信息传输全部是以明文方式,不够安全,很容易被 ...

  10. OkHttp3源码详解(五) okhttp连接池复用机制

    1.概述 提高网络性能优化,很重要的一点就是降低延迟和提升响应速度. 通常我们在浏览器中发起请求的时候header部分往往是这样的 keep-alive 就是浏览器和服务端之间保持长连接,这个连接是可 ...