hdu5308-Brain Tonic-pat

Source: Internet
Author: User

First put the results of the PAT:



Sentiment: can obviously find the subscript difference 1 of the relationship, so to deal with this need a lot of brain repair water problem, really egg pain, before used to pat, only know there is such a thing, the program is hand calculation, artificial simulation (often brain fever, severe lack of oxygen), so tried once to shoot, actually feel to deal with the water problem yy , especially works ...

Test instructions: To an n value, representing n N, using +,-,*,/four operations to construct 24 points, each number can only be used once, and after one operation of the number can only be used once, printing out the operation process.

Ideas: belong to the brain hole big open topic, really need very strong yy ability, first 1-3 certainly not, output 1, then the remaining number, because to gather enough 24 this value, so you can divide into 24=4*6, then yy, (N+n+n+n)/n=4,6 is the same truth, So it takes 12 N to make up 24 this value, then the next number only to all 0 can, but the special is 13 this value, because 12 number you used up, there is also how can not be 0, so here to yy under how to take, 13 after the number of laws are like this, So you just yy4-13 these values can, in addition YY finished, this code write up special egg ache, I don't say anything, can try it myself.


#include <iostream> #include <stdio.h> using namespace std;
        void solve (int n) {string str[] = {"-1", "1", "-1", "1 * 2\n5 + 3\n6 + 4", "1 * 2\n6 * 3\N7-4\N8/5", "1 + 2\n7 + 3\n8 + 4\n9 + 5\n10-6", "1 + 2\n8 + 3\n4 + 5\n10 + 6\n11" /7\n9 + "," 1 + 2\n9 + 3\n4 + 5\n11-6\n12-7\n13/8\n10 + + "," 1 + 2\n10 + 3\n4 + 5\n12 + 6\n13/ 7\n11-14\n15-8\n16 + 9 "," 1 + 2\n3 + 4\n12 + 5\n13 + 6\n14/7\n11 + 15\n8-9\n17/10\n16 + 18 "," 1  + 2\n3 + 4\n13/5\n12 + 14\n15-6\n16 + 7\n17-8\n18 + 9\n19-10\n20 + One "," 1 + 2\n3 + 13\n4 + 14\n5 + 6\n7 + 16\n8 + 17\n9 + 15\n10 + 19\n18/11\n20/12\n21 *, "1 + 2\n3 + 4\n15/5\n14-16\n17-6\n18 + 7\n19-8\n  + 9\n21-10\n22 + 11\n23-12\n24 + ",//" 1 + 2\n3 +%d\n4 +%d\n5 + 6\n7 +%d\n8 +%d\n9 +%d\n10 +%d\n%d
    /11\n%d/12\n%d *%d\n "};
cout<<str[n-1]<<endl; }
void solve1 (int n) {//printf ("1 + 2\n3 +%d\n4 +%d\n5 + 6\n7 +%d\n8 +%d\n9 +%d\n10 +%d\n11-12\n%d *%d\n", n
    +1,N+2,N+4,N+5,N+6,N+7);
    for (int i=1;i<=n-14;i++)//printf ("%d *%d\n", n+9+i-1,14+i);
    printf ("%d *%d\n%d/13\n%d/14\n%d +%d\n", n+3,n+8,n+10,n+11,n+12,n+9); printf ("1 + 2\n3 +%d\n4 +%d\n5 + 6\n7 +%d\n8 +%d\n9 +%d\n10 +%d\n%d/11\n%d/12\n%d *%d\n13-14\n", n+1,n+2,n+4,n
    +5,N+3,N+7,N+6,N+8,N+9,N+10);
    for (int i = 15,k=0; I <= n; ++i,k++) printf ("%d *%d\n", i,n+12+k);

printf ("%d +%d\n", n + 11,2*n-2);
    } int main () {int n;
        while (cin>>n) {if (n<=13) solve (n);
    if (n>=14) solve1 (n);
 }
}


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.