Broken Door Lock

Source: Internet
Author: User


A few years ago, before Sun Lu served as GDUTACM Training Team coach, the days of training team were very bleak, the table in the laboratory was very old, it collapsed, and the training team were miserable. Fortunately, under the leadership of Sun boss, training Team Day to a well-off, all things are gradually have, printers (of course, laser) what, high-speed Internet (10+m downloads per second) or something. More importantly, training team's spending on the go-out is doubling, and it looks sure to continue to grow, in short, training team is striding forward.

Bathed in the reform and opening up of the spring breeze, the moon in the white cotton-like clouds through, the breeze blowing a happy song, the players sit in the high valley pile next to listen to the story of the elder boss told the past.

At that time, training team did not lock the door, we can only use a not know how long the password lock to lock the door(It's the one that locks the bike .), this password lock has3bits, each with1~NTotalNa number, where1and theNadjacent(because it's a circle .), the password lock has a user password(A1,B1,C1), there is also a factory password(A2,B2,C2) (because it's a fake manufacturer, so it 's a pit-dad.= =). More pit father is, because of years of disrepair, when the person who opened the door to use the password and the correct password for each of the difference is not more than2, the door lock will open. (Fall! )

For example, the user password is(a), the factory password is(4,5,6),Nto be9, this time, if you use a password(1,9,5)The door lock will be opened because it differs from the user's password separately.(0,2,2). Similarly, the password(2,4,8)You can also open the door because the gap between it and the factory password is(2,1,2). But(1,5,6)is not possible, because it and the user password gap is(0,3,3),and the factory password gap is(3,0,0).

Now, Sun Lu asks you, how many passwords can open this broken door lock.

The first line of input data has only one number, which indicates the number of test data.

Next, each group of data accounted for 3 rows.

The first line has only one number N (1<=n<=100):

The next line has three numbers that represent the user's password.

The third line has three numbers that indicate the factory password. Output a row for each set of data, indicating how many passwords can be unlocked. Sample Input
1501 2 35) 6 7
Sample Output
249
AC code: Each group of data has a maximum of 250 answers, 5*5*5*2,
#include <iostream> #include <cstdio> #include <cmath>using namespace std;int n;int tt (int a,int b) {  //Find out the number of duplicates int t,q,w;if (a>b) {t=a;a=b;b=t;} Q=b-a;w=n+a-b;q=min (q,5);   can only be 5w=min (w,5); return 10-q-w;} int main () {int t,i,j;int a[3],b[3];while (cin>>t) while (t--) {cin>>n;for (i=0;i<3;i++)     cin>> A[i];    for (i=0;i<3;i++)    cin>>b[i];if (n>5) {j=1;    for (i=0;i<3;i++)    J*=tt (A[i],b[i]);    Cout<<250-j<<endl;} else Cout<<pow (n,3) <<endl;} return 0;}


Broken Door Lock

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.