hdu6789 Fight(暴力枚举)

#include<bits/stdc++.h>
typedef  long long ll ;
#define mod 99999997
#define gcd __gcd
#define rep(i , j , n) for(int i = j ; i <= n ; i++)
#define red(i , n , j)  for(int i = n ; i >= j ; i--)
#define ME(x , y) memset(x , y , sizeof(x))
#define INF  0x3f3f3f3f
#define PI acos(-1)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define size(v) (int)(v.size())
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define int ll
using namespace std;
const int maxn = 1e5+9;
const int N = 35;

//此题要抓住本质,最优解与打架的先后顺序无关,只与ab,bc,ac各打了几次
//所以枚举ab,bc打了几次.就能确定ac打了几次答案取最小值
void solve(){
    int x , y , z ;
    scanf("%lld%lld%lld" , &x , &y , &z);
    int xy = di((ll)1000 , max(x , y));
    int yz = di((ll)1000 , max(y , z));
    int ans = INF;
    rep(i , 0 , xy){//枚举ab
        int fa = 1000 - i*y;
        int fb = 1000 - i*x;
        int fc = 1000 ;
        rep(j , 0 , yz){
            int b = fb - j*z;
            int c = fc - j*y;
            int a = fa ;
            int k = 0;
            if(a > 0 && b > 0 && c > 0){
                if(di(a , z) == di(c , x)){//如果ac能够同时消灭,则是一组解,否则不能组成一组解
                    ans = min(ans , i+j+di(a , z));
                }
                continue;
            }
            if(a > 0 && b > 0 && c <= 0){//c已经被消灭
                k = min(di(a , y) , di(b , x));
                ans = min(ans , i+j+k);
            }
            else if(b > 0 && c > 0 && a <= 0){//a已经被消灭
                k = min(di(b , z) , di(c , y));
                ans = min(ans , i+j+k);
            }
            else if(a > 0 && c > 0 && b <= 0){//b已经被消灭
                k = min(di(a , z) , di(c , x));
                ans = min(ans , i+j+k);
            }
            else{//已经有两个消灭了
                ans = min(ans , i+j);
            }
        }
    }
    printf("%lld\n" , ans);
}

signed main()
{
/*#ifdef ONLINE_JUDGE
#else
    freopen("D:\\c++\\in.txt", "r", stdin);
#endif*/
    int t ; scanf("%lld" , &t); while(t--)
        solve();
}

posted @ 2020-07-26 18:51  无名菜鸟1  阅读(164)  评论(0编辑  收藏  举报