zoukankan      html  css  js  c++  java
  • Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker

                                                  C. Bear and Poker
                                                                     time limit per test 
    2 seconds
                                                                     memory limit per test 
    256 megabytes
     

    Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars.

    Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?

    Input

    First line of input contains an integer n (2 ≤ n ≤ 105), the number of players.

    The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — the bids of players.

    Output

    Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.

    Sample test(s)
    input
    4
    75 150 75 50
    output
    Yes
    input
    3
    100 150 250
    output
    No
    Note

    In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.

    It can be shown that in the second sample test there is no way to make all bids equal.

    题意:给你n个数,每个数可以乘2或3,问你是否能让所有数相同;

    题解:先找出最大公约数,再不断除2,3,判断是否是1就好了

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <queue>
    #include <typeinfo>
    #include <map>
    #include <stack>
    typedef __int64 ll;
    #define inf 0x7fffffff
    using namespace std;
    inline ll read()
    {
        ll x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9')
        {
            if(ch=='-')f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9')
        {
            x=x*10+ch-'0';
            ch=getchar();
        }
        return x*f;
    }
    //**************************************************************************************
    
    ll  gcd(ll a,ll b)
    {
        if(b==0)return a;
        else return gcd(b,a%b);
    }
    int A[100005];
    int main()
    {
        int n=read();
        ll a=read();
        int cnt=0;
        A[++cnt]=a;
        for(int i=1;i<n;i++)
        {
           int  b=read();
           A[++cnt]=b;
           a=gcd(a,b);
        }
        int flag=0;
        for(int i=1;i<=n;i++)
        {
            A[i]/=a;
            while(A[i]%2==0)A[i]=A[i]/2;
            while(A[i]%3==0)A[i]=A[i]/3;
            if(A[i]!=1){
                flag=1;
                cout<<"NO"<<endl;
                break;
            }
        }
        if(!flag)cout<<"YES"<<endl;
        return 0;
    }
    代码
  • 相关阅读:
    No-3.Linux 终端命令格式
    No-2.常用 Linux 命令的基本使用
    No-1.文件和目录
    No-7.运算符
    No-6.If语句
    No-5.变量的命名
    YOLOv4详细分析 | 细数当前最佳检测框架小细节(附论文及源码下载)
    案例】S7-200SMART 实时时钟如何在MCGS触摸屏上显示并写入
    卡尔曼滤波:从入门到精通
    mmdetection最小复刻版(七):anchor-base和anchor-free差异分析
  • 原文地址:https://www.cnblogs.com/zxhl/p/4770406.html
Copyright © 2011-2022 走看看