HDU 5610 Baby Ming and Weight lifting

Source: Internet
Author: User

Baby Ming and Weight lifting

Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 1365 Accepted Submission (s): 500

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 respectively A 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.

Inputin the first line contains a single positive integer $T $, indicating number of test case.
For each test case:
There is three positive integer A, B, and C.
1<t<1000, 0 < A, B, C <=, a! = B  Outputfor each test case, if the barbell weighted $C $ Can ' t is made up, print impossible.
Otherwise, print numbers to indicating the numbers of $a $ and $b $ barbell disks is needed. (If there is more than one answer, print the answer with minimum $a +b$) Sample Input21 2 61 4 5 Sample Output2 2Impossible  Main topic: 2 Types of barbell tablets (weight A and B, respectively), each type of barbell plate has an unlimited number. Use these 2 kinds of barbell plates to form a weight C barbell (barbell must be balanced). The number of A, B (if there are multiple answers, the output a+b the smallest scheme) idea: The great God method too dick, 982MS over
#include <stdio.h>intMain () {intI, J, T, A, B, C, flag; scanf ("%d", &t);  while(t--) {scanf ("%d%d%d", &a, &b, &c); if(c&1) {printf ("impossible\n"); Continue; }         for(c/=2, flag=0, i=0;! flag&&i<= -; i++)//Number of A+b                 for(j=0;! flag&&j<=i;j++)//Number of B                        if((i-j) *a+j*b==c&& (flag=1)) printf ("%d%d\n", (I-J) <<1, j<<1); if(!flag) printf ("impossible\n"); }        return 0;}



HDU 5610 Baby Ming and Weight lifting

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.