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