您的位置:首页 > 其它

hdoj-5610-Baby Ming and Weight lifting

2016-05-16 21:55 162 查看
[align=left]Problem Description[/align]
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.



[align=left]Input[/align]
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

[align=left]Output[/align]
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)

[align=left]Sample Input[/align]

2
1 2 6
1 4 5


[align=left]Sample Output[/align]

2 2
Impossible


这个应该就是直接枚举出来的吧

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
int t,m,i,j,k;
scanf("%d",&t);
while(t--){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if( c%2!=0)
{
printf("Impossible\n");continue;
}
bool bj=false;
int x=2000,y=2000;
for(i=0;i<=c;i++){
int tmp=i*a;
if(tmp > c) break;
for(j=0;j<=c;j++){
int t=j*b;
if(t > c) break;
if( (t+tmp)*2==c ){
if((x+y)>(i+j)){
x=i,y=j;
}
bj=true;
}
}
}
if(bj)
printf("%d %d\n",x*2,y*2);
else
printf("Impossible\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: