标签:you detection actual problem cannot tab ++ wan can
#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; }
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.
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 the number of basic ID numbers for which the given table cannot detect one or more common human errors
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
0
这个题目把题意读懂了就好写了,比较简单,直接暴力就可以,不过有很多细节。
2292: Quality of Check Digits 中南多校 暴力枚举
标签:you detection actual problem cannot tab ++ wan can
原文地址:https://www.cnblogs.com/EchoZQN/p/10634069.html