Codeforces 573 A. Bear and Poker

简介:

click here~~

                                     A. Bear ***and Poker***

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.
AI 代码解读

题目大意:给你一个数m,同时有m个数arr[i],如果每个数能够翻倍或者是翻三倍能够使所有的数相等就输出YES,否则输出NO。

解题思路:就是看,每个数除以2或者3看最后的结果是不是相等就行了

上代码:

/*
2015 - 9 - 1 晚上
Author: ITAK

今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
*/
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;

const int maxn = 1e5 + 5;

int arr[maxn];

int Judge(int x)
{
    while(x%2==0)
        x/=2;
    while(x%3==0)
        x/=3;
    return x;
}
int main()
{
    int m;
    while(~scanf("%d",&m))
    {
        for(int i=0; i<m; i++)
            scanf("%d",&arr[i]);
        ///cout<<Judge(m)<<endl;
        int ans = Judge(arr[0]);
        bool flag = false;
        for(int i=1; i<m; i++)
        {
            if(ans != Judge(arr[i]))
            {
                flag = true;
                break;
            }
        }
        if(flag)
            puts("NO");
        else
            puts("YES");
    }
    return 0;
}
AI 代码解读
目录
打赏
0
0
0
0
2
分享
相关文章
codeforces 322 B Ciel and Flowers
有红绿蓝三种颜色的画,每种拿三朵可以组成一束花,或者各拿一朵组成花束,告诉你每种花的数目,求出可能组成最多的花束。 如果你的代码过不了,考虑一下 8 8 9这种组合。 因为数据量很大,我的思想就是局部和总体采用不同的策略。
64 0
|
10月前
codeforces
【6月更文挑战第10天】
64 0
【论文阅读】(2017)The late acceptance Hill-Climbing heuristic
【论文阅读】(2017)The late acceptance Hill-Climbing heuristic
626 0
【论文阅读】(2017)The late acceptance Hill-Climbing heuristic
CodeForces 1195C Basketball Exercise (线性DP)
CodeForces 1195C Basketball Exercise (线性DP)
136 0
Codeforces 833E Caramel Clouds
E. Caramel Clouds time limit per test:3 seconds memory limit per test:256 megabytes input:standard input output:standard out...
1181 0
Codeforces 791A Bear and Big Brother(暴力枚举,模拟)
A. Bear and Big Brother time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard ou...
1300 0