【Acwing】第57场周赛 题解

 


AcWing 4485. 比大小

 

输入样例1:

5
1 2 3 4 5
2 1 4 3 5

输出样例1:

Yes

输入样例2:

5
1 1 1 1 1
1 0 1 0 1

输出样例2:

Yes

输入样例3:

3
2 3 9
1 7 9

输出样例3:

No

AC代码 

#include <iostream>
using namespace std;
typedef long long LL;
int main()
{
    LL res1 = 0, res2 = 0;
    int n; cin >> n;
    for(int i = 0; i < n; i ++ ) 
    {
        int num1; cin >> num1; 
        res1 += num1;
    }
    for(int i = 0; i < n; i ++ ) 
    {
        int num1; cin >> num1; 
        res2 += num1;
    }
    if(res1 >= res2) puts("Yes");
    else puts("No");
    return 0;
}

AcWing 4486. 数字操作 

输入样例1:

20

输出样例1:

10 2

输入样例2:

5184

输出样例2:

6 4

解题思路 

算术分解定理可知:\small n=p_1^{\alpha _1}p_2^{\alpha _2}\cdots p_n^{\alpha _n} 

由题意可知,最后操作完最后最小的结果就是 \small res=p_1*p_2\cdots p_k

我们需要找到一个 \small 2^m 满足 \small 2^m\geqslant \alpha _i ,然后通过一次操作使得所有的质因子的次数都为 \small 2^m

如果所有质因子的次数恰好都为 \small 2^m ,则不需要这一步操作

剩下的就是把 \small 2^m 开根号至 \small 2^0 即可 。


AC代码

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n; cin >> n;
    
    int res = 1, m = 0;
    vector<int> a;
    for(int i = 2; i * i <= n; i ++ )
        if(n % i == 0)
        {
            int c = 0;
            while(n % i == 0) n /= i, c ++ ;
            res *= i;
            a.push_back(c);
            while(1 << m < c) m ++ ;
        }
    if(n > 1) 
    {
        res *= n;
        a.push_back(1);
        while(1 << m < 1) m ++ ;
    }
    
    for(auto x : a)
        if(x < 1 << m)
        {
            m ++ ;
            break;
        }
    
    cout << res << ' ' << m << endl;
    
    return 0;
}

AcWing 4487. 最长连续子序列

输入样例1:

5
100 200 1 1 1

输出样例1:

3

输入样例2:

5
1 2 3 4 5

输出样例2:

0

输入样例3:

2
101 99

输出样例3:

1

 解题思路

题目所给的条件上本质上是求在这段区间上的平均数

通过前缀和的思想,即满足下列公式 \frac{S_i-S_j}{i-j}>100 \Leftrightarrow S_i-S_j > (i-j)\times 100

令 b_i=a_i-100 问题等价于,一段区间和(bi)满足大于0

AC代码

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 1000010;

int n;
LL s[N];
int stk[N];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++ )
    {
        int x; scanf("%d", &x);
        s[i] = s[i - 1] + x - 100;
    }
    
    int top = 0, res = 0;
    stk[++ top] = 0;
    for(int i = 1; i <= n; i ++)
    {
        if(s[stk[top]] > s[i]) stk[++ top] = i;
        else if(s[stk[top]] < s[i])
        {
            int l = 1, r = top;
            while(l < r)
            {
                int mid = l + r >> 1;
                if(s[stk[mid]] < s[i]) r = mid;
                else l = mid + 1;
            }
            res = max(res, i - stk[r]);
        }
    }
    cout << res << endl;
    
    return 0;
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

玄澈_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值