CSU1600: Twenty-four point (DFS)

Source: Internet
Author: User

CSU1600: Twenty-four point (DFS)
Description

Given four numbers, can you get twenty-four through the addition, subtraction, multiplication, and division? Each number can be used only once.

 

Input

The input consists of multiple test cases. each test case contains 4 integers A, B, C, D in a single line (1 <= A, B, C, D <= 13 ).

 

Output

For each case, print the "Yes" or "No". If twenty-four point can be get, print "Yes", otherwise, print "No ".

 

Sample Input
2 2 3 91 1 1 1 5 5 5 1
Sample Output
YesNoYes
HINT

 

For the first sample, (2/3 + 2) * 9 = 24.

 

Source
Question: four digits. You can use the four arithmetic operations to see if you can get 24 o'clock.
Idea: for such a small amount of data, you do not need to doubt your life
#include 
 
   #include 
  
    #include 
   
     #include 
    
      #include 
     
       #include
       #include 
       
         #include 
        
          #include 
         
           #include using namespace std; #define ls 2*i #define rs 2*i+1 #define up(i,x,y) for(i=x;i<=y;i++) #define down(i,x,y) for(i=x;i>=y;i--) #define mem(a,x) memset(a,x,sizeof(a)) #define w(a) while(a) #define LL long long const double pi = acos(-1.0); #define Len 200005 #define mod 19999997 const int INF = 0x3f3f3f3f; #define exp 1e-8 double a[5]; bool dfs(double *a,int n) { if(n==1) return fabs(a[0]-24)
          
         
        
       
     
    
   
  
 

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.