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;
    }
    代码
  • 相关阅读:
    CUDA内存介绍
    CUDA10.0 官方手册 阅读笔记 章三 CUDA编程接口
    Texture Gather 讲解
    cuda学习--纹理内存
    计算机缓存Cache以及Cache Line详解
    nvidia的cuda编程api
    将ORBSLAM往ANDROID STUDIO 移植的时候一些坑
    解决Android10读取不到/sdcard/、/storage/emulated/0/文件的问题
    Android NDK 从入门到精通(汇总篇)
    好好说说c++内存序--以单例模式为例子
  • 原文地址:https://www.cnblogs.com/zxhl/p/4770406.html
Copyright © 2011-2022 走看看