hdoj-5610-Baby Ming and Weight lifting
2016-05-16 21:55
162 查看
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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
[align=left]Output[/align]
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)
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
这个应该就是直接枚举出来的吧
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.
[align=left]Input[/align]
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
[align=left]Output[/align]
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)
[align=left]Sample Input[/align]
2 1 2 6 1 4 5
[align=left]Sample Output[/align]
2 2 Impossible
这个应该就是直接枚举出来的吧
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; int main(){ int t,m,i,j,k; scanf("%d",&t); while(t--){ int a,b,c; scanf("%d%d%d",&a,&b,&c); if( c%2!=0) { printf("Impossible\n");continue; } bool bj=false; int x=2000,y=2000; for(i=0;i<=c;i++){ int tmp=i*a; if(tmp > c) break; for(j=0;j<=c;j++){ int t=j*b; if(t > c) break; if( (t+tmp)*2==c ){ if((x+y)>(i+j)){ x=i,y=j; } bj=true; } } } if(bj) printf("%d %d\n",x*2,y*2); else printf("Impossible\n"); } return 0; }
相关文章推荐
- 机器学习中使用的神经网络第六讲笔记
- Python 格式化字符串
- 正则表达式(Regular Expressions)
- Build错误TransformException:java.exe
- Ubuntu16.04下开发Openni+Nite+OpenCv3.1
- Petya and Java
- #1050 : 树中的最长路
- 动态规划2之1003
- ROS(indigo)_pr2_simulator仿真(gazebo)示例
- bash 语法篇
- ROS(indigo)_pr2_simulator仿真(gazebo)示例
- ROS(indigo)_pr2_simulator仿真(gazebo)示例
- 数据库查询优化方案(处理上百万级记录如何提高处理查询速度)
- 写了一个登陆界面
- 编译生成动态库文件(方式二)
- Python点滴(五)-pandas进阶
- iOS 隐藏键盘的通用方法
- 46.把字符串转换成整数
- tensorflow + pycharm安装即相关资料
- php 回调、匿名函数和闭包