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为奇数的时候显然不行。 由于有多组答案的时候输出铁圈数之和小的。。。那么我们枚举的话。应该把里面那层枚举的变量放置成重量较大的。。。。
/* ***********************************************
Author :111qqz
Created Time :2016年01月23日 星期六 18时56分38秒
File Name :code/bc/#69/1001.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6int a,b,c;
7int main()
8{
9 #ifndef ONLINE_JUDGE
10 freopen("code/in.txt","r",stdin);
11 #endif
1 int T;
2 cin>>T;
3 while (T--)
4 {
5 bool isswap = false;
6 scanf("%d %d %d",&a,&b,&c);
7 if (c%2==1)
8 {
9 puts("Impossible");
10 continue;
11 }
12 c/=2;
13 if (a>b)
14 {
15 swap(a,b);
16 isswap = true;
17 }
18 bool ok = false;
19 for ( int i = 0 ; i*a<=c ;i++)
20 {
21 for ( int j = 0 ; i*a+j*b <= c ; j++)
22 {
23 if (i*a+j*b==c)
24 {
25 ok = true;
26 if (isswap) cout<<j*2<<" "<<i*2<<endl;
27 else cout<<i*2<<" "<<j*2<<endl;
28 break;
29 }
30 }
31 if (ok) break;
32 }
33 if (!ok)
34 {
35 puts("Impossible");
36 }
37 }
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}