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

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

  

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

  1. hdu 5612 Baby Ming and Matrix games(dfs暴力)

    Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...

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

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

    Baby Ming and phone number Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  4. Codeforces Round #346 (Div. 2)---E. New Reform--- 并查集(或连通图)

    Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory lim ...

  5. BestCoder Round 69 Div 2 1001&& 1002 || HDU 5610 && 5611

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5610 如果杠铃总质量是奇数直接impossible 接着就考验耐心和仔细周全的考虑了.在WA了三次后终于发 ...

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

  7. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  8. Codeforces Round #356 (Div. 2)A. Bear and Five Cards(简单模拟)

    A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. Codeforces Round #248 (Div. 2) C. Ryouko's Memory Note (vector 替换)

    题目链接 题意:给m个数字, 这些数字都不大于 n,  sum的值为相邻两个数字 差的绝对值.求这n个数字里把一个数字 用 其中另一个数字代替以后, 最小的sum值. 分析:刚开始以为两个for 最坏 ...

随机推荐

  1. Proxifier设置代理

    1.首先需要开启http代理选项---配置文件->高级->HTTP代理服务器,勾选“启用HTTP代理服务器支持” 2.然后开始添加代理服务器选择“配置文件->代理服务器”,在弹出框点 ...

  2. 设置COOKIE过期时间的方法

    第一,日期运算法 1)将期限设置为当前日期后的第N天的0时0分0秒 Response.Cookies(LastView).Expires=dateadd(d,N,date) 2)将期限设置为当前日期后 ...

  3. ubuntu - chrome 标题栏, 书签乱码 解决

    只要修改/etc/fonts/conf.d/49-sansserif.conf这个文件就行了—— 打开/etc/fonts/conf.d/49-sansserif.conf这个文件: sudo ged ...

  4. 【应聘】阿里巴巴Java面试题目

    原文地址:http://blog.csdn.net/free0sky/article/details/7927275   一.String,StringBuffer, StringBuilder 的区 ...

  5. Java-泛型编程-使用通配符? extends 和 ? super

    原文地址:http://blog.csdn.net/fw0124/article/details/42296283 泛型中使用通配符有两种形式:子类型限定<? extends xxx>和超 ...

  6. html5极速3D立体式图片相册切换效果

    下载Demo  

  7. 升级WordPress

    1. 备份文件 mv wordpress wordpress_3.6 2. 下载新版本 wget http://cn.wordpress.org/wordpress-3.8-zh_CN.zip 3. ...

  8. iE6、7、8、9、10、11兼容的Cookie

    <%@ Master Language="C#" Debug="true" AutoEventWireup="true" Inheri ...

  9. HDU 5437 Alisha’s Party

    题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ...

  10. Android 嵌套GridView,ListView只显示一行的解决办法

    重写ListView.GridView即可: public class MyListView extends ListView { public MyListView(Context context) ...