noip2008 Match Stick equation

Source: Internet
Author: User

P1149 Match Stick equation
      • 1.9K through
      • 3.7K Submit
    • Topic provider The user does not exist
    • Tag Search/Enumeration simulation Noip raise group
    • Difficulty Popularization-

Submit a discussion of the problem record

Title Description

Give you n a match stick, you can spell how many shape like "a+b=c" equation? A, B, and C in the equation are integers that are spelled with a match stick (if the number is nonzero, the highest bit cannot be 0). Spell the number 0-9 with a match stick:

Attention:

    1. The plus sign and the equals sign each need two sticks

    2. If A≠b, A+b=c and b+a=c are considered different equations (A, B, c>=0)

    3. N sticks must all be used.
Input output Format input format:

The input file matches.in a total of one line, and another integer n (n<=24).

Output format:

The output file matches.out a common line that represents the number of different equations that can be spelled.

Input and Output Sample input example # #:
Sample input 1:14 Example input 2:18
Sample # # of output:
Sample output 1:2 Sample output 2:9
Description

"Input and output Example 1 explanation"

2 equations for 0+1=1 and 1+0=1.

"Input and output Example 2 explanation"

The 9 equations are:

0+4=40+11=111+10=112+2=42+7=94+0=47+2=910+1=1111+0=11
Analysis: This problem is not very difficult, the first to use an array to 0~9 number of matches needed to show the number of match sticks, but more than 9 how to express it? A 10 binary natural number is made up of 0~9, then we can get the number of each position in the MOD10, and then calculate it according to the data in the array. However, it is important to note that the operation symbol also counts the number of matches.
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;intN,ans =0;ints[Ten] = {6,2,5,5,4,5,6,3,7,6};intShuliang (intx) {    if(x = =0)    return 6; intsum =0;  while(X >0) {sum+ = s[x%Ten]; X/=Ten; }    returnsum;}intMain () {scanf ("%d",&N);  for(inti =0; I < +; i++)     for(intj =0; J < +; J + +)    {        intA = Shuliang (i) +Shuliang (j); intb = Shuliang (i +j); if(A + B +4==N) Ans++; } printf ("%d", ans); return 0;}

noip2008 Match Stick equation

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.