zoukankan      html  css  js  c++  java
  • P2651 添加括号III

    题目传送门

    一、解题思路

    这道题有些意思,因为(a)肯定是分子,怎么想办法也不可能变成分母。(b)肯定是分母,怎么的也变不成分子。(c,d,e,f...)就是有可能是分子,也有可能是分母,尽量想办法让它们全是分子,这样出现整数的概率高,出现在分母,还得想办法去约分掉它,麻烦。(贪心)

    那它们是否真的能都是分子呢?可以的,只要在不同的地方加上小扩号,就可全都翻上去,变成分子!!!!

    遇事不决,小学数学:

    1、在乘除混合运算中“去括号”或添“括号”的方法:

    (① a imes (b div c) = a imes b div c)

    (② a div (b imes c)=a div b div c)

    (③ a div (b div c)=a div b imes c)

    2、举例

    $①1320×500÷250=1320×(500÷250)=1320×2=2640 $

    (②4000÷125÷8=4000÷(125×8)=4000÷1000=4)

    (③5600÷(28÷6)=5600÷28×6=200×6=1200)

    明白了吧,我们现在用的是性质(3),就是连除法,可以转为(a×c÷b),其它的类似,都翻到分子上去,分母只保留 (a)

    二、C++代码

    #include <bits/stdc++.h>
    
    using namespace std;
    int t;
    
    //最大公约数
    int gcd(int x, int y) {
        return y ? gcd(y, x % y) : x;
    }
    int main() {
        cin >> t;
        while (t--) {
            int n;
            cin >> n;
            //一次读入第一个和第二个
            int a, b;
            cin >> a >> b;
            b /= gcd(a, b);//去掉a,b公因子,目标是b=1,a已经发近挥不出来力量啦
            //逐个读入,逐个约分
            for (int i = 3; i <= n; i++) {
                int x;
                cin >> x;
                b /= gcd(x, b);
            }
            if (b == 1) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    webuploader web 大文件上传源代码
    poj 1703 Find them, Catch them
    poj 1308 Is It A Tree?
    hud 1785 畅通工程
    食物链 poj 1182
    poj 1611 The Suspects 并查集
    poj 2524 并查集 Ubiquitous Religions
    The Suspects 简单的并查集
    cf 621D
    hdu2159
  • 原文地址:https://www.cnblogs.com/littlehb/p/15210882.html
Copyright © 2011-2022 走看看