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.

题目大意:给你一个数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;
}
时间: 2024-12-13 03:38:29

Codeforces 573 A. Bear and Poker的相关文章

CodeForces 653 A. Bear and Three Balls——(IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2))

传送门 A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Limak is a little polar bear. He has n balls, the i-th ball has size ti. Limak wants to give one ball to each of

Codeforces 574 A. Bear and Elections

cilck here ~~ ***A. Bear and Elections*** Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote

Codeforces 574 B. Bear and Three Musketeers

Cilck Here~~ B. Bear and Three Musketeers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Rich

codeforces 336C Vasily the Bear and Sequence

点击打开codeforce 336C 思路; 位运算 分析: 1 题目要求找到k个数,使得这k个数的&的结果能够被2^v整除,并且v的值应该要尽量的大 2 一个数能够被2^v整数,说明这个数的二进制的最右边的1后面刚好是v个0,比如20的二进制为10100,那么刚好可以被2^2整除,那么就有最右边的1的后面0的个数刚好为2个 3 那么我们可以通过从大到小枚举v,然后我们去n个数里面找满足"这个数的二进制的最右边的1后面刚好是v个0",然后进行求&运算,只要我们找到一个满

Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (数学、dp)

C. Little Elephant and LCM time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output The Little Elephant loves the LCM (least common multiple) operation of a non-empty set of positive integers. The

Codeforces B. Taxi 算法题解

简单总结题意: 有一个数组,数组中的数值不会大于4,即只能是1,2,3,4,要把这些数值装进一个容量最大为4的容器里面,使得所用到这样的容器的个数最小. 经测试数据很大,会有10万个数据,所以这里我并不用排序数据,而是使用counting sort的思想,根据特定的数据优化,使得题解时间复杂度为O(n). 更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/ 程序如下: #include <iostream>

CodeForces 233B Non-square Equation

链接: http://codeforces.com/problemset/problem/233/B 题目: B. Non-square Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Let's consider equation: x2+s(x)·x-n=0, where x,n are positive

CodeForces:200C: Football Championship

地址链接: CF:  http://codeforces.com/problemset/problem/200/C HUST Virtual Judge: http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=28923 题目: C. Football Championship time limit per test 2 seconds memory limit per test 256 megabytes input s

UVa 131 The Psychic Poker Player:枚举&amp;amp;模拟好题

131 - The Psychic Poker Player Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=67 In 5-card draw poker, a player is dealt a hand of five cards (which may