zoukankan      html  css  js  c++  java
  • 西交校赛 F. GZP and Poker

    F. GZP and Poker

    GZP often plays games with his friends.Today they went to a board game.There are n players(including GZP) and all of them have some virtual money on the table. ith of them has ai yuan.
    Each player can double his virtual wealth any number of times and triple his virtual wealth any number of times.The game has a big prize for making wealth of all players equal.Is it possible for GZP and his friends to win the big prize?
     

    Input

    The input consists of several test cases.
    First line of input contains an integer n(2n10^5),the number of players.
    The second line contains n integer numbers a1,a2,,an(1ai10^9)-the virtual money of players.
     

    Output

    For each test case, print a line.
    "Yes"(without the quotes)if players can make their wealth equal, or "No" otherwise.
     

    Sample Input

    4
    75 150 75 50
    3
    100 150 250

    Sample Output

    Yes
    No


    题意

    问这些数能否经过变成同一个数,变换为乘2或者3,乘的次数任意;

    思路

    temp=a[i]*2^x*3*y;
    可以发现
    a[i]*2^x*3*y=a[j];
    这里的x和y为整数;那么就可以搜索了;

    AC代码

    #include <bits/stdc++.h>
    using namespace std;
    #define Riep(n) for(int i=1;i<=n;i++)
    #define Riop(n) for(int i=0;i<n;i++)
    #define Rjep(n) for(int j=1;j<=n;j++)
    #define Rjop(n) for(int j=0;j<n;j++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    typedef long long LL;
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=0x3f3f3f3f;
    const int N=1e5+5;
    int n;
    LL a[N];
    map<LL,int>mp;
    int dfs(LL x)
    {
        mp[x]=1;
        if(2*x<=3e9+7&&!mp[2*x])
        {
            dfs(2*x);
        }
        if(3*x<=3e9+7&&!mp[3*x])
        {
            dfs(3*x);
        }
        if(x%2==0&&!mp[x/2])
        {
            dfs(x/2);
        }
        if(x%3==0&&!mp[x/3])
        {
            dfs(x/3);
        }
    }
    int solve()
    {
        for(int i=2;i<=n;i++)
        {
            if(!mp[a[i]])
            {
                printf("No
    ");
                return 0;
            }
        }
        printf("Yes
    ");
        return 0;
    }
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            mp.clear();
            Riep(n)
            {
                scanf("%lld",&a[i]);
            }
            dfs(a[1]);
            solve();
    
        }
    
        return 0;
    }
  • 相关阅读:
    用JS获取地址栏参数的方法(超级简单)
    js全选
    梦幻西游手游三界奇缘答题 文字解答
    父级div height:auto无效解决办法
    DropDownList赋值,绑定,传值
    《梦幻西游》手游人宠抗防修炼点修消耗表
    使客户端的控件ID保持不变,不受母版页的影响
    无法读取项目文件 .csproj
    七天学会ASP.NET MVC (一)——深入理解ASP.NET MVC
    MVC控件解析
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5468885.html
Copyright © 2011-2022 走看看