hdu 5610 ||BC #69 div2 1001 Baby Ming and Weight lifting

http://acm.hdu.edu.cn/showproblem.php?pid=5610 题意:有重量为a,b两种铁圈每种无限多个…能能否组成一个重量为c且平衡杠铃(中间的杆的重量忽略不计) a,b,c都是整数。 思路:平衡的话。。就是两边重量一样。。那么c为奇数的时候显然不行。 由于有多组答案的时候输出铁圈数之和小的。。。那么我们枚举的话。应该把里面那层枚举的变量放置成重量较大的。。。。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年01月23日 星期六 18时56分38秒
 4File Name :code/bc/#69/1001.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33int a,b,c;
34int main()
35{
36	#ifndef  ONLINE_JUDGE 
37	freopen("code/in.txt","r",stdin);
38  #endif
39
40	int T;
41	cin>>T;
42	while (T--)
43	{
44	    bool isswap = false;
45	    scanf("%d %d %d",&a,&b,&c);
46	    if (c%2==1)
47	    {
48		puts("Impossible");
49		continue;
50	    }
51	    c/=2;
52	    if (a>b)
53	    {
54		swap(a,b);
55		isswap = true;
56	    }
57	    bool ok = false;
58	    for ( int i =  0 ; i*a<=c ;i++)
59	    {
60		for ( int j = 0 ; i*a+j*b <= c ; j++)
61		{
62		    if (i*a+j*b==c)
63		    {
64			ok = true;
65			if (isswap) cout<<j*2<<" "<<i*2<<endl;
66			    else cout<<i*2<<" "<<j*2<<endl;
67			break;
68		    }
69		}
70		if (ok) break;
71	    }
72	    if (!ok)
73	    {
74		puts("Impossible");
75	    }
76	}
77
78  #ifndef ONLINE_JUDGE  
79  fclose(stdin);
80  #endif
81    return 0;
82}