HDU 5610 Baby Ming and Weight lifting violence

Source: Internet
Author: User

Problem Descriptionbaby Ming is fond of weight lifting. He has a barbell pole (the weight of which can being ignored) and a different kinds of barbell disks (the weight of which are respectivelya and b), the amount of each one being infinite.
Baby Ming prepare to use this, kinds of barbell disks to make up a new one weighted C(The Barbell Must is balanced), he want to know how to do it.

Inputin The first line contains a single positive integerT, indicating number of test case.
For each test case:
There is three positive integera,b , andC.
1≤T≤0<a,b,C≤,a≠ b
Outputfor Each test case, if the barbell weightedCCan ' t is made up, print impossible.
Otherwise, print numbers to indicating the numbers of< Span id= "mathjax-span-46" class= "Mrow" >a  and  b  barbell disks is needed. (If there is more than one answer, print the answer with Minimum  a+ b )
Sample Input21 2 4 5 Sample Output2 2Impossible The Chinese meaning is to give you a barbell that can be put on the bar, the equivalent of a weight can be placed on both sides of the lever .... Give you the mass of two weights (infinite quantity) and ask if you can make the entire lever a weight of c. Initially thought to be moving the rules, found that the data range is only 1000, so the direct violence enumerated. However, to make the large number from large to small enumeration, after all, most of the solution output the smallest one. The code is as follows:
1#include <cstdio>2#include <cmath>3#include <cstring>4#include <iostream>5 using namespacestd;6 intn,a,b,c;7 BOOLBo,bo1;8 intMain () {9scanf"%d",&n);Ten      while(n--) One     { Ado{false; -bo1=false; -scanf" %d%d%d",&a,&b,&c); the         if(c%2!=0) -printf"impossible\n"); -         Else -         { +c=c/2; -         if(a>b) +         { A Swap (A, b); atbo1=true; -         } -          for(intI= +; i>=0;--i) -         { -              for(intj= +; j>=0;--j) -             { in                   if(b*i+a*j==c&&bo1==true) -                   { toprintf"%d%d\n",2*i,2*j); +do{true; -                    Break; the}Else if(b*i+a*j==c) { *                    $printf"%d%d\n",2*j,2*i);Panax Notoginsengdo{true; -                  Break; the     } +             } A             if(bo==true) the              Break; +         } -         if(bo!=true) $printf"impossible\n"); $     } -     } -     return 0; the}

HDU 5610 Baby Ming and Weight lifting violence

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.