西交校赛 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(2≤n≤10^5),the number of players.

The second line contains n integer numbers a1,a2,?,an(1≤ai≤10^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\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        mp.clear();
        Riep(n)
        {
            scanf("%lld",&a[i]);
        }
        dfs(a[1]);
        solve();

    }

    return 0;
}
时间: 2024-08-09 06:22:11

西交校赛 F. GZP and Poker的相关文章

西交校赛 I. GZP and CS(数位dp)

I. GZP and CS GZP love to play Counter-Strike(CS). One day GZP was playing a mod of CS. The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to

北邮校赛 F. Gabriel&#39;s Pocket Money(树状数组)

F. Gabriel's Pocket Money 2017- BUPT Collegiate Programming Contest - sync 时间限制 2000 ms 内存限制 65536 KB 题目描述 For centuries, Heaven has required its young angels to live and study among humans in order to become full-fledged angels. This is no different

西电校赛网络赛J题 lucas定理计算组合数

西电校赛网络赛J题  lucas定理计算组合数 问题 J: 找规律II 时间限制: 1 Sec  内存限制: 128 MB 提交: 96  解决: 16 [提交][状态][讨论版] 题目描述 现有数阵如下: 1    2  3   4     5    6 1   3   6  10  15 1   4  10   20 1   5   15 1    6 1 求这个数阵的第n行m列是多少(行列标号从1开始) 结果对10007取模 输入 多组数据,每组数据一行,包含两个整数n,m(1<=n<=

广州工业大学2016校赛 F 我是好人4 dfs+容斥

Problem F: 我是好人4 Description 众所周知,我是好人!所以不会出太难的题,题意很简单 给你n个数,问你1000000000(含1e9)以内有多少个正整数不是这n个数任意一个的倍数 最后友情提供解题代码(我真是太好人了) void solve(int p[], int n) { int ans = 0; for (int i = 1; i <= 1e9; i++) { int fl = 0; for (int j = 0; j < n; j++) { if (i % p[

2015 whu校赛f题big data(dp + 小技巧)

题意是给定五个数n(n <= 100),a,b,l,r 另外有函数序列f(x),其中f(x + 1) = f(x) + a或f(x)+ b,f(0) = 0,问有多少个这样的函数序列f(1)到f(n)使得函数序列的和在l和r之间 解题思路如下: 图片有一处错误,要减去的是a*(n + 1) * n而不是 (b - a)* (n + 1) * n,此外,要注意x/c时向上取整和向下取整的问题. 这道题做做停停一个月了今天终于找时间ac了,有点感人呐 代码如下: #include<cstdio&g

xdu2017校赛F

Problem F Dogs of Qwordance Senior Backend R&D Engineers 问题描述 那年夏天,锘爷和杰师傅漫步在知春公园的小道上.他们的妻子.孩子牵 着狗在前面嬉戏,二人笑语盈盈,他们不深究一个小的编程问题,而是对整个 Qwordance (四字舞蹈)公司的发展前景加以描绘.这样的场景,想想就觉得好 美,想想就好向往,想想就好激动.然而,他们的狗觉得这非常的无聊,决定自 己去玩. 杰师傅的狗非常挑剔.它希望找到一块面积为 x 的长方形广场,还要求广 场的长

hust校赛 f题 The tree of hust(lis 变形)

题目大意是给出一段数字序列,可以忽略一次一段连续的序列,求忽略后的最长连续上升子序列 思路是dp,用end数组记录以当前元素作为结尾的最长连续上升序列的元素个数,那么不难得到状态转移方程为 dp(i) = max(dp(i - 1),  max( end[k] ) ) + 1 代码如下: #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostr

第九届西电ACM校赛解答

Description 欢迎参加西电第九届ACM校内赛!作为一名经历了四届校赛的ACM老队员以及本次校赛的出题人,每次校赛都让我有一种全新的感受--有第一次参加校赛时提交代码时紧张到双手发抖,也有当裁判时看到有些不明真相的人提交编译后程序时的欢乐.不管你是第几次参赛,好好享受这一刻带给你的各种感受,经历就是一种财富.为了让大家更好地记住这悲喜交加的日子,特意准备了这么一道题: 给你一个日期,你只要输出这个日期是在校赛前还是校赛后,或者刚好就是校赛那一天(2011年5月22号). 题目是什么意思呢

校赛总结

写写校赛总结....... 这两次校赛是我们组队以后第一次的比赛...第一场打得很拙,第二场还可以吧,第一场校赛--毕竟是期待了很久的校赛,所以感觉还是很紧张,吃饭的时候打了二两,剩了一大半==, 这次我们队名叫 I_Love_High_Math......没走到现场,就快下雨了,真的有点郁闷==.到了以后下雨了,和一个队友被困雨中,,出来以后衣服湿了,一开始就悲剧了...     然后一开场就感觉不好.比赛开始的时候,我去写头文件,然后W说A是水题,然后叫我写,平时都是我写第一题的这次我不想开