Baby Ming and Weight lifting
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 681 Accepted Submission (s): 280
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 ofa and b barbell disks are needed. (If there is more than one answer, print the answer with minimum a+b)
Sample Input21 2 61 4 5
Sample Output2 2Impossible
Sourcebestcoder Round #69 (Div.2)
Test instructions: There is a B two kinds of barbell plate, the weight of the barbell bar is ignored, the two kinds of plates have unlimited, now let you use these two kinds of plate to make a new barbell C asked how many (n,m) a B if there are many schemes, take n+m least
Note: Both ends of the barbell must be equal in weight,
Analysis 1, the value of C must be even 2, make C must be a number of a and B number are even (can be 0)
Problem: Because the topic data is not big, so directly enumerate all cases
#include <stdio.h> #include <string.h> #include <string> #include <math.h> #include < Algorithm> #define LL Long long#define PI atan (1.0) *4#define DD doublea#define MAX 10100#define mod 10007using namespace Std;int Ans[max];int Main () { int n,m,j,i,t,k; int a,b,c,min1,x,y; scanf ("%d", &t), while (t--) { scanf ("%d%d%d", &a,&b,&c); n=m=0; if (c&1) { printf ("impossible\n"); Continue; } min1=1000000;x=y=0; for (i=0;i<=1000;i+=2) {for (j=0;j<=1000;j+=2) { if (c==i*a+j*b) { if (i+j <min1) { x=i;y=j; Min1=i+j ; }}}} if (min1>10000) printf ("impossible\n");
Bestcoder Round #69 (Div.2) Baby Ming and Weight lifting (Hdu 5610)