zoukankan      html  css  js  c++  java
  • 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
    ");
    	   	    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
    ");
    	   else printf("%d %d
    ",x,y);
    	}
    	return 0;
    } 
    

      

  • 相关阅读:
    Python脚本传參和Python中调用mysqldump
    金蝶K3管理软件PDA条码解决方式,盘点机与金蝶K3无缝对接
    android设置中的Preferencescreen使用方法介绍与分析
    设计模式之6大原则(3)-依赖倒置原则
    C# DataTable的詳細使用方法
    C++学习笔记13-类继承
    hdu1023
    Haskell 差点儿无痛苦上手指南
    三角形、长方形、正方形、梯形、圆等的周长计算公式和面积计算公式
    (黑客游戏)HackTheGame1.21 过关攻略
  • 原文地址:https://www.cnblogs.com/tonghao/p/5178376.html
Copyright © 2011-2022 走看看