BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

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 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.

 

 

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.

1T1000,0<a,b,C1000,ab
 

 

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)
 

 

Sample Input
2
1 2 6
1 4 5
 

 

Sample Output
2 2
Impossible
 

 

Source

 题意:有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;
} 

  

posted @ 2016-02-02 19:29  非我非非我  阅读(153)  评论(0编辑  收藏  举报