HDU 5610 Baby Ming and Weight lifting (enumeration)

Source: Internet
Author: User

Baby Ming and Weight liftingTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 1439 Accepted Submission (s): 525


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 how to do it.


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 ≤ +,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 Input

Sample Output
2 2Impossible

Sourcebestcoder Round #69 (Div.2)
Recommendhujie | We have carefully selected several similar problems for you:5674 5673 5672 5671 5669 enumerate through each case.
#include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;int main () {int t,m,n,i , j,k,l,sum,minn,maxx,num,flag,a,ans1,ans2;scanf ("%d", &t), while (t--) {scanf ("%d%d%d", &m,&n,&sum) ; if (sum%2) {printf ("impossible\n"); continue;}    Else{minn=min (N,M); Maxx=max (n,m);} if (maxx*2>sum)//cannot be used with large {if (Sum%minn) printf ("impossible\n"); Else{if (sum/minn%2) printf ("impossible\n"); else{num        =sum/minn;        if (minn==m) printf ("%d 0\n", num); else printf ("0%d\n", num);}} } else {flag=0; l=sum/maxx; for (i=l;i>=0;i--) {if (flag) break, if ((Sum-i*maxx)%minn==0) {if (flag) break; A= (sum-i*m Axx)/minn; for (j=i;j>=0;j--) {if (flag) break, for (k=0;k<=a;k++) {if (K*MINN+J*MAXX==SUM/2)//If it can be made up of half, compare wit one place {ans1=i; Ans2=a; flag=1; }}}}} if (flag==0) printf ("impossible\n"); if (flag==1) {if (minn==m) printf ("%d%d\n", ans2,ans1), Else printf ("%d%d\n", ans1,ans2);}}} return 0;}

HDU 5610 Baby Ming and Weight lifting (enumeration)

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.