zoukankan      html  css  js  c++  java
  • 浙江理工2015.12校赛-G Jug Hard

    Jug Hard
    Time Limit: 10 Sec Memory Limit: 128 MB
    Submit: 1172 Solved: 180
    Description

    You have two empty jugs and tap that may be used to fill a jug. When filling a jug from the tap, you can only fill it completely (i.e., you cannot partially fill it to a desired level, since there are no volume measurements on the jug).

    You may empty either jug at any point.

    You may transfer water between the jugs: if transferring water from a larger jug to a smaller jug, the smaller jug will be full and there will be water left behind in the larger jug.

    Given the volumes of the two jugs, is it possible to have one jug with some specific volume of water?
    Input

    The first line contains T, the number of test cases (1 ≤ T 100 000). Each test case is composed of three integers: a b d where a and b (1 ≤ a, b ≤ 10 000 000) are the volumes of the two jugs, and d is the desired volume of water to be generated. You can assume that d ≤ max(a,b).
    Output

    For each of the T test cases, output either Yes or No, depending on whether the specific volume of water can be placed in one of the two jugs.
    Sample Input

    3
    8 1 5
    4 4 3
    5 3 4

    Sample Output

    Yes
    No
    Yes

    an+bn=d;
    证明等式的成立,就是扩展欧几里得的证明

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    
    int GCD(int a,int b)
    {
        return b==0?a:GCD(b,a%b);
    }
    
    int main()
    {
        int T;
        int n ,m,d;
    
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d %d %d",&n,&m,&d);
            printf("%s
    ",d%GCD(n,m)==0?"Yes":"No");
    
        }
        return 0;
    }
    
  • 相关阅读:
    什么是静态测试、动态测试、黑盒测试、白盒测试、α测试 β测试
    软件产品质量特性
    目前主要的测试用例设计方法是什么?
    软件的安全性应从哪几个方面去测试?
    软件配置管理的作用?软件配置包括什么?
    HDOJ1003(DP)
    HDOJ5650
    POJ1068(模拟)
    POJ2586(贪心)
    HDOJ1548(BFS)
  • 原文地址:https://www.cnblogs.com/juechen/p/5255900.html
Copyright © 2011-2022 走看看