Problem Description
Baby Ming is fond of weight lifting. He has a barbell pole(the weight of which can be ignored) and two 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 two kinds of barbell disks to make up a new one weighted C(the barbell must be balanced), he want to know how to do it.
Baby Ming prepare to use this two kinds of barbell disks to make up a new one weighted C(the barbell must be balanced), he want to know how to do it.
Input
In the first line contains a single positive integer
T, indicating number of test case.
For each test case:
There are three positive integer a,b, and C.
1≤T≤1000,0<a,b,C≤1000,a≠b
For each test case:
There are three positive integer a,b, and C.
1≤T≤1000,0<a,b,C≤1000,a≠b
Output
For each test case, if the barbell weighted
C can’t be made up, print Impossible.
Otherwise, print two numbers to indicating the numbers of a and b barbell disks are needed. (If there are more than one answer, print the answer with minimum a+b)
Otherwise, print two numbers to indicating the numbers of a and b barbell disks are needed. (If there are more than one answer, print the answer with minimum a+b)
Sample Input
2
1 2 6
1 4 5
Sample Output
2 2
Impossible
中文意思大概是给你一个可以放杠铃片的杠铃,相当于一个可以在两边放重物的杠杆。。。。
给你两个重物的质量(数量无限),问是否能使整个杠杆的重量为C。
一开始还以为要动规,发现数据范围只有1000,所以直接暴力枚举过了。
不过要让大数从大到小枚举,毕竟多数解时输出最小的那个。
代码如下:
1 #include<cstdio> 2 #include<cmath> 3 #include<cstring> 4 #include<iostream> 5 using namespace std; 6 int n,a,b,c; 7 bool bo,bo1; 8 int main(){ 9 scanf("%d",&n); 10 while(n--) 11 { 12 bo=false; 13 bo1=false; 14 scanf("%d %d %d",&a,&b,&c); 15 if (c%2!=0) 16 printf("Impossible\n"); 17 else 18 { 19 c=c/2; 20 if (a>b) 21 { 22 swap(a,b); 23 bo1=true; 24 } 25 for(int i=1000;i>=0;--i) 26 { 27 for(int j=1000;j>=0;--j) 28 { 29 if (b*i+a*j==c&&bo1==true) 30 { 31 printf("%d %d\n",2*i,2*j); 32 bo=true; 33 break; 34 }else if(b*i+a*j==c){ 35 36 printf("%d %d\n",2*j,2*i); 37 bo=true; 38 break; 39 } 40 } 41 if (bo==true) 42 break; 43 } 44 if (bo!=true) 45 printf("Impossible\n"); 46 } 47 } 48 return 0; 49 }