Vijos P1496 match Stick equation "the second question of NOIP2008 raising group"

Source: Internet
Author: User

Title Link: https://vijos.org/p/1496

Main topic:

Give you n (n<24) A match stick, you can spell out how many shape like "a+b=c" equation? ("+" and "=" Each need two match sticks)

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

N sticks must all be used.

Topic Ideas:

In fact, the problem is very water, n maximum only 24, deducted + and = Only 20, direct enumeration on the line.

Just a little bit to know that each number will not exceed 1111.

Two-level for enumerates each number, judging whether the match is exhausted.

 

1 //2 //by Coolxxx3 //4#include <iostream>5#include <algorithm>6#include <string>7#include <iomanip>8#include <memory.h>9#include <time.h>Ten#include <stdio.h> One#include <stdlib.h> A#include <string.h> -#include <stdbool.h> -#include <math.h> the #defineMin (a) < (b) ( A):(B)) - #defineMax (a) (a) > (b)? ( A):(B)) - #defineABS (a) ((a) >0? ( A):(-(a))) - #defineLowbit (a) (a& (a)) + #defineSqr (a) (a) * (a) - #defineSwap (a) (a) ^= (b), (b) ^= (a), (a) ^= (b) + #defineEPS 1e-8 A #defineS 10000 at #defineMAX 2139062143 - #definePI 3.1415926535897 - #defineN 34 - #defineM 1111 - using namespacestd; - intN,m,cas,lll,ans; in inta[4]; - intr[Ten]={6,2,5,5,4,5,6,3,7,6}; to intCalintaa) + { -cas=0; the     if(aa==0)return 6; *      for(cas=0; aa;aa/=Ten) $cas+=r[aa%Ten];Panax Notoginseng     returnCAs; - } the voidWork () + { A     inti,j,x,y,z; the      for(i=0; i<m;i++) +     { -x=cal (i); $         if(x>=n-1)Continue; $Z=cal (i+i); -         if(x+x+z==N) -         { theans++; -             //printf ("%d+%d=%d\n", i,i,i+i);Wuyi         } the          for(j=i+1; j<=m;j++) -         { Wuy=Cal (j); -             if(x+y>=n-1)Continue; AboutZ=cal (i+j); $             if(x+y+z==N) -             { -ans+=2; -                 //printf ("%d+%d=%d\n", i,j,i+j); A             } +         } the     } - } $ intMain () the { the #ifndef Online_judge the //freopen ("1.txt", "R", stdin); the //freopen ("2.txt", "w", stdout); -     #endif in     inti,j,k; the //while (~scanf ("%s", s)) the      while(~SCANF ("%d", &n) &&N) About     { theans=0; then-=4; the Work (); +printf"%d\n", ans); -     } the     return 0;Bayi } the  the  - /* - // the  the // the */
View Code

Vijos P1496 match Stick equation "the second question of NOIP2008 raising group"

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.