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.

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)

Sample Input

2

1 2 6

1 4 5

Sample Output

2 2

Impossible

Source

BestCoder Round #69 (div.2)

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

  

时间: 2024-10-18 03:01:43

BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)的相关文章

HDU 5610 Baby Ming and Weight lifting(枚举)

Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1439    Accepted Submission(s): 525 Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(t

HDU 5610 Baby Ming and Weight lifting

Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1365    Accepted Submission(s): 500 Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(th

[Codeforces Round #146 (Div. 1) B]Let&#39;s Play Osu!(期望Dp)

Description You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be

BestCoder Round #69 (div.2)(hdu5611)

Baby Ming and phone number Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1501    Accepted Submission(s): 399 Problem Description Baby Ming collected lots of cell phone numbers, and he wants to

HDU 5610 Baby Ming and Weight lifting 暴力

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

BestCoder Round #69 (div.2)

A.geometry #include<cstdio> #include<vector> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int main(){ //freopen("in.txt","r",stdin); int T;scanf("%d",&T); whi

Codeforces Round #393 (Div. 2) E题Nikita and stack(线段树)解题报告

Nikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer x on the top of the stack, and operation pop() deletes the top integer from the stack, i. e. the last added. If the stack

Codeforces Round #384 (Div. 2) B. Chloe and the sequence(规律题)

传送门 Description Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following algorithm of generating a

【打CF,学算法——二星级】Codeforces Round #313 (Div. 2) B. Gerald is into Art(水题)

[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/B 题面: B. Gerald is into Art time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Gerald bought two very rare paintings at the Sotheby's a