The Asia regional Contest, Tsukuba quality of Check Digits gym-101158b

Source: Internet
Author: User

Test instructions: A city citizen each has a five-digit ID, the first four bits is the basic ID, the last one is the check digit, the check digit is based on the sample given table, the ID of a citizen is ABCDE, then E= ((((0$a) $b) $d), every citizen can make mistakes, For example, if one digit is wrong or the adjacent two is swapped, then our excellent table should be able to judge the situation of error, we know that for the correct ID, (((((((((((() $b) $d) $e) = 0, but equal to 0 is not necessarily correct, not equal to 0 must be wrong, We are asking for the four-bit basic ID we can not verify that this is the correct number of IDs, that is, as long as this ID error condition may be sentenced to correct, then it is not possible, ans will be Gaga

Practice: Direct Simulation

Pit point: For example, 1233 33 after the exchange with the original value return value is the same, so even if the same can not be judged correct, because the 33 exchange is the original value, here special consideration can be.

The code is as follows:

#include <stdio.h>#include<iostream>#include<string.h>#include<algorithm>using namespacestd;intmp[Ten][Ten];intnum[Ten];intans;//int vis[10];intsolve_1 () {intres =0;  for(intI=0; i<4; i++) {res=Mp[res][num[i]]; }    returnRes;}intsolve () {intres =0;  for(intI=0; i<=4; i++) {res=Mp[res][num[i]]; }    returnRes;}BOOLok () {//memset (Vis, 0, sizeof (VIS));    intttmp;  for(intI=0; i<5; i++) {ttmp=Num[i];  for(intj=0; j<Ten; J + +)        {            if(j==ttmp)Continue; Num[i]=J; if(Solve () = =0)                return false; } Num[i]=ttmp; }    if(num[0]! = num[1]) {Swap (num[0], num[1]); if(Solve () = =0)            return false; Swap (num[0], num[1]); }    if(num[1]! = num[2]) {Swap (num[1], num[2]); if(Solve () = =0)            return false; Swap (num[1], num[2]); }    if(num[2]! = num[3]) {Swap (num[2], num[3]); if(Solve () = =0)            return false; Swap (num[2], num[3]); }    if(num[3]! = num[4]) {Swap (num[3], num[4]); if(Solve () = =0)            return false; }    return true;}intMain () {ans=0;  for(intI=0; i<Ten; i++)         for(intj=0; j<Ten; J + +) scanf ("%d", &Mp[i][j]);  for(intI=0; i<Ten; i++)    {         for(intj=0; j<Ten; J + +)        {             for(intp=0; p<Ten; p++)            {                 for(intq=0; q<Ten; q++) {num[0] =i; num[1] =J; num[2] =p; num[3] =Q; num[4] =solve_1 (); if( !OK ()) {ans++;//printf ("%d%d%d%d \ n", Num[0], num[1], num[2], num[3], num[4]);}}}}} printf ("%d\n", ans); return 0;}

The Asia regional Contest, Tsukuba quality of Check Digits gym-101158b

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.