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
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.
For each test case:
There are three positive integer a,b, and C.
1≤T≤1000,0<a,b,C≤1000,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)
题意:有A B两种杠铃盘,杠铃杆的重量忽略,这两种盘都有无限个,现在让你用这两种盘来制作新的杠铃C问需要A B多少个(n,m) 如果有多种方案,取n+m最少的
注意:杠铃的两端必须重量相等,
分析1、c的值必须为偶数2、制作c必须使A的个数和B的个数都为偶数(可以为0)
题解:因为题目数据不大 所以直接枚举所有情况
#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 10007
using 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");
else printf("%d %d\n",x,y);
}
return 0;
}