Baby Ming and Weight lifting(BestCoder)

来源:互联网 发布:大数据培训班多少钱 编辑:程序博客网 时间:2024/05/29 09:33

纯暴力,做的时候太心急了错了两遍。。

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>#include <queue>using namespace std;const int maxn = 100010;int T, n;int main() {    scanf("%d", &T);    while(T--) {        int a, b, c;        scanf("%d%d%d", &a, &b, &c);        int ans = 10000000;        int A, B; bool ok = false;        for(int i = 0; i <= c; ++i) {            int num = (c - i * a) / b;            if(i * a + b * num == c) {                bool is = false;                for(int j = 0; j <= i; ++j) {                    for(int k = 0; k <= num; ++k) {                        if(j * a + k * b == c - j * a - k * b) {                            is = true;                            goto leap;                        }                    }                }                leap:                    if(is && ans > i + num) {                        A = i;                        B = num;                        ans = i + num;                        ok = true;                    }            }        }        if(!ok) printf("Impossible\n");        else printf("%d %d\n", A, B);    }    return 0;}


0 0
原创粉丝点击