[Analog] Hdu 5308 I wanna become A 24-point Master

Source: Internet
Author: User

Test instructions

Give you n number, each number is N,

Then the n number is subtraction, each number must be used once, and only once, and the number of computations will have to be used once.

That is to do n-1 times, ask can get 24, output process XI? XJ number I and the number of J do? Operation this form

Ideas:

Because N is likely to be large, it certainly requires a perfect structure.

The simplest way is to construct a 4*6

Constructs 4 needs 5 numbers, constructs 6 needs 7 numbers

That means at least 12 numbers, the remaining number is subtracted to 0, and then the multiplication is good.

But it's important to note that 13 doesn't satisfy this rule.

So 1~13 special sentence, more than 14 of the output by law is good ~

Code:

#include "cstdlib" #include "Cstdio" #include "CString" #include "Cmath" #include "queue" #include "algorithm" #include "    Iostream "using namespace Std;int main () {int n;            while (scanf ("%d", &n)!=-1) {if (n<=3) {puts ("-1");        Continue            } if (n==4) {puts ("1 * 2");            Puts ("5 + 3");            Puts ("6 + 4");        Continue            } if (n==5) {puts ("1 * 2");            Puts ("6 * 3");            Puts ("7-4");            Puts ("8/5");        Continue            } if (n==6) {puts ("1 + 2");            Puts ("3 + 4");            Puts ("5-6");            Puts ("7 + 8");            Puts ("9 + 10");        Continue            } if (n==7) {puts ("1 + 2");            Puts ("8 + 3");            Puts ("9/4");            Puts ("5/6");            Puts ("7 + 11");            Puts ("12 * 10");        Continue      } if (n==8) {      Puts ("1 + 2");            Puts ("9 + 3");            Puts ("5-4");            Puts ("6 * 11");            Puts ("7 * 12");            Puts ("8 * 13");            Puts ("10 + 14");        Continue  } if (n==9) {puts ("1/2"); 1 puts ("3-10");  8 Puts ("4 + 5"); Puts ("12 + 6"); Puts ("13/7");  3 puts ("One by One *"),//15 puts ("8-9");            0 puts ("15 + 16");        Continue  } if (n==10) {puts ("1 + 2");  Puts ("3 + 4");  Puts ("5 + 6");  Puts ("7-8"); 0 puts ("9 * 14");            0 puts ("+ +"),//16 puts ("16/10"),//17 4 puts ("17 + 11");//18 24            Puts ("18 + 15");        Continue  } if (n==11) {puts ("1 + 2");  Puts ("3 + 4");    13 22        Puts ("13/5");  2 puts ("+ +"),//15 ("6-7") puts; 0 puts ("8 * 16"); 0 puts ("9 * 17"); 0 puts ("Ten *"),//19 0 puts ("one *"),//20 0 puts ("+ +)",//21 C        Ontinue; } if (n==12) {puts ("1 + 2");//13 2n printf ("%d + 3\n", n+1);//14 3n printf ("%d + 4\n", n+2); 4n printf ("%d + 5\n", n+3); 5n printf ("%d + 6\n", n+4); 6n printf ("%d/7\n", n+5); (n+6) 6 puts ("8 + 9"); 2n printf ("%d + 10\n", n+7); 3n printf ("%d + 11\n", n+8); 4n printf ("%d/12\n", n+9); (N+10) 4 printf ("%d *%d\n", n+6,n+10);        (N+11) Continue;  } if (n==13) {puts ("1/2"); 1 puts ("3-14");  Puts ("4 + 5"); Puts ("16/6"); 17 2           Puts ("//18"); puts ("7-8"); 0 puts ("9 * 19"); 0 puts ("10 * 20"); 0 puts ("11 * 21"); 0 puts ("12 * 22"); 0 puts ("13 * 23"); 0 puts ("24 + 18");        Continue; } puts ("1 + 2"); 2n printf ("%d + 3\n", n+1); 3n printf ("%d + 4\n", n+2); 4n printf ("%d + 5\n", n+3); 5n printf ("%d + 6\n", n+4); 6n printf ("%d/7\n", n+5); (n+6) 6 puts ("8 + 9"); 2n printf ("%d + 10\n", n+7); 3n printf ("%d + 11\n", n+8); 4n printf ("%d/12\n", n+9); (N+10) 4 printf ("%d *%d\n", n+6,n+10);        (n+11) puts ("13-14");//n+12 0 int tep=n+12;            for (int i=15;i<=n;i++) {printf ("%d *%d\n", i,tep);        tep++;    } printf ("%d +%d\n", n+11,tep); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[Analog] Hdu 5308 I wanna become A 24-point Master

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.