HDU 5610 Baby Ming and Weight lifting(模拟)

题目地址:点击打开链接

思路:a和b的个数肯定是成对出现的,暴力模拟一下就行,比赛的时候还以为a和b都得用了,结果不用也行

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>

typedef long long ll;
using namespace std;

int main()
{
    int t,a,b,c;
    int i,j;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&a,&b,&c);
        if(c % 2 == 1)
        {
            printf("Impossible\n");
            continue;
        }
        int max1 = 2010;
        int x1,x2;
        for(i=0; i<=1000; i+=2)
        {
            for(j=0; j<1000; j+=2)
            {
                if(i*a+j*b > c)
                {
                    break;
                }
                if(i*a+j*b == c && i+j<max1)
                {
                    max1 = i+j;
                    x1 = i;
                    x2 = j;
                }
            }
        }
        if(max1 == 2010)
        {
            printf("Impossible\n");
            continue;
        }
        printf("%d %d\n",x1,x2);
    }
    return 0;
}


你可能感兴趣的:(HDU 5610 Baby Ming and Weight lifting(模拟))