Monoxer Programming Contest 2022(AtCoder Beginner Contest 238)部分题解

A - Exponential or Quadratic
B - Pizza
C - digitnum


A - Exponential or Quadratic

思路: 先将n变成 n 2 n^2 n2用一个变量 a a a储存起来,用一个循环从1遍历到 n n n
看看 2 n 2^n 2n会不会在某个时候与 n 2 n^2 n2相等。
code:

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main()
{
    int n;
    cin>>n;
    ll b=n*n;
    for(int i=1;i<=n;i++)
    {
        ll a=pow(2,i);
        if(a>b){cout<<"Yes"<<endl;return 0;}
    }
    cout<<"No"<<endl;
    return 0;
}

B - Pizza

思路: 用一个动态数组来储存每次切的角度,最后排序求之间最大差值即可。还有一点需要注意的就是0和360都要放进数组里。
code:

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{
    int n,now=0;
    vector<int>q;
    cin>>n;
    q.push_back(0);
    while(n--)
    {
        int k;
        cin>>k;
        now+=k;
        now%=360;
        q.push_back(now);
    }
    q.push_back(360);
    sort(q.begin(),q.end());
    int res=0;
    for(int i=1;i<q.size();i++)
        res=max(res,q[i]-q[i-1]);
    cout<<res<<endl;
    return 0;
}

C - digitnu

思路: 观察 f ( 1 ) ∼ f ( n ) f(1)\sim f(n) f(1)f(n)可以将 n n n分割成 ( 1 ∼ 9 ) (1\sim 9) (19), ( 10 ∼ 99 ) (10 \sim 99) (1099) ( x , n ) (x,n) (x,n),在这个过程成就可以分开计算其和值。然后本题还有一个点需要注意,那就是取模,这里到某个时候和值会很大,然后观察可以发现等差数列的性质,求和就可以像下面这样子写:

ll calc(ll x)
{
    x%=mod;
    ll res=x;
    res*=(x+1);
    res%=mod;
    res*=inv2;//这里相当于除以2操作,inv2的值为mod的两倍
    res%=mod;
    return res;
}

完整代码:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 998244353, inv2 = 499122177;
ll calc(ll x)
{
    x%=mod;
    ll res=x;
    res*=(x+1);
    res%=mod;
    res*=inv2;
    res%=mod;
    return res;
}
int main()
{
    ll n;
    cin>>n;
    ll res=0,p10=10;
    for(int i=1;i<=18;i++)
    {
        ll l=p10/10;
        ll r=min(n,p10-1);
        if(l<=r)
        {
            res+=calc(r-l+1);
            res%=mod;
        }
        p10*=10;
    }
    cout<<res<<endl;
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

我不是北泽吖

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

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

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

打赏作者

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

抵扣说明:

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

余额充值