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. js二维码扫描

    Cordova 3.x 实用插件(2) -- 二维码Barcode : http://rensanning.iteye.com/blog/2034026 samples-camera: http:// ...

  2. git设置对比工具

    windows下设置 beyond compare 3 为 git  的对比工具. 首先需要先安装 beyond compare 3 工具,切记需要安装安装版的,不要搞绿色版的. mac下使用 Kal ...

  3. enum,struct,union类型使用和长度

    VC,C++ Builder和lcc三个编译器 间枚举类型enum长度的情况. 各种C编译器默认的字节对齐数不一致,要写通用的代码,经常就是使用 #pragma pack(1) ... #pragma ...

  4. hdu 4911 Inversion (分治 归并排序 求逆序数)

    题目链接 题意:给n个数,求交换k次相邻的数之后的最小的逆序数对. 用分治的方法,以前在poj上做过这种题,昨天比赛的时候忘了.... 下面的归并排序还是以前的模板. #include <ios ...

  5. bzoj2242: [SDOI2011]计算器 && BSGS 算法

    BSGS算法 给定y.z.p,计算满足yx mod p=z的最小非负整数x.p为质数(没法写数学公式,以下内容用心去感受吧) 设 x = i*m + j. 则 y^(j)≡z∗y^(-i*m)) (m ...

  6. 转:ASP.NET MVC中Unobtrusive Ajax的妙用

    Unobtrusive Javascript有三层含义:一是在HTML代码中不会随意的插入Javsscript代码,只在标签中加一些额外的属性值,然后被引用的脚本文件识别和处理:二是通过脚本文件所增加 ...

  7. 【流媒體】live555—VS2010 下live555编译、使用及测试

    Ⅰ live555简介 Live555 是一个为流媒体提供解决方案的跨平台的C++开源项目,它实现了对标准流媒体传输协议如RTP/RTCP.RTSP.SIP等的支持.Live555实现了对多种音视频编 ...

  8. 【转】STL空间配置器

    STL空间配置器(allocator)在所有容器内部默默工作,负责空间的配置和回收.STL标准为空间配置器定义了标准接口(可见<STL源码剖析>P43).而具体实现细节则由各编译器实现版本 ...

  9. Spring 定时任务的实现<转>

    本人暂时用到的实现定时任务的方式有2种 一.注解方式实现,简单方便 1:在applicationContext.xml中加入下面的配置, 这是spring的组件扫描,保证含有定时任务的类,能被spri ...

  10. iOS数据存储之属性列表理解

    iOS数据存储之属性列表理解 数据存储简介 数据存储,即数据持久化,是指以何种方式保存应用程序的数据. 我的理解是,开发了一款应用之后,应用在内存中运行时会产生很多数据,这些数据在程序运行时和程序一起 ...