Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1)A,B

本文探讨了熊Limak参与扑克游戏,并通过调整赌注大小来尝试赢得赌场的巨奖。同时,还介绍了Limak如何通过快速摧毁塔块来解决构建塔的问题,涉及到数学逻辑与算法策略的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.
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.

思路:求出最大公约数,除掉之后看是不是只包含2和3

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
const int maxn=100010;
int N,a[maxn];
bool judge(int x){
    while(x%2==0)x/=2;
    while(x%3==0)x/=3;
    return x==1;
}
int main(){
    while(scanf("%d",&N)!=EOF){
        int g=1;
        for(int i=1;i<=N;i++){
            scanf("%d",&a[i]);
            if(i==1)g=a[i];
            else g=__gcd(g,a[i]);
        }
        bool flag=true;

        for(int i=1;i<=N;i++){
            a[i]/=g;
            if(!judge(a[i])){
                flag=false;
                break;
            }
        }
        printf("%s\n",flag?"Yes":"No");
    }
    return 0;
}

B. Bear and Blocks

Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample.

Limak will repeat the following operation till everything is destroyed.

Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.

Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.
Input

The first line contains single integer n (1 ≤ n ≤ 105).

The second line contains n space-separated integers h1, h2, …, hn (1 ≤ hi ≤ 109) — sizes of towers.
Output

Print the number of operations needed to destroy all towers.
Sample test(s)
Input

6
2 1 4 6 2 2

Output

3

Input

7
3 3 3 1 3 3 3

Output

2

Note

The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.
这里写图片描述
After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.

思路:对于第i列,一次操作之后变成min(h[i]-1,h[i+1],h[i-1])所以先预处理出从左从右分别消除的次数,然后取最大值即可

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
const int maxn=100010;
int N,H[maxn];
int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++)scanf("%d",&H[i]);
    H[1]=1;
    for(int i=2;i<=N;i++)H[i]=min(H[i],H[i-1]+1);
    H[N]=1;
    for(int i=N-1;i>=1;i--)H[i]=min(H[i],H[i+1]+1);
    int ans=0;
    for(int i=1;i<=N;i++)ans=max(ans,H[i]);
    printf("%d\n",ans);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值