codeforces Round #574(Div.2) Problem-D1. Submarine in the Rybinsk Sea (easy edition)

题目链接:http://codeforces.com/contest/1195/problem/D1

 

 

 

 

这题比赛期间没通过,赛后才补的题

题意就不再讲了,挺容易理解,注意理解公式表达的意思就行了。

分析:

我的想法比较暴力(所以也没通过哈)。就是先算出公式的值,然后相加取模。

code:

#include <cstdio>
#include <stack>

using namespace std;
typedef long long LL;
const int MAXN = (int) 1e5 + 7;

LL array[MAXN];

LL func(LL x, LL y)
{
    stack<int> s;
    LL res = 0;
    int cnt = 1;
    while(x || y)
    {
        if(cnt&1)
        {
            s.push(y%10);
            y /= 10;
        }
        else
        {
            s.push(x%10);
            x /= 10;
        }
        cnt ++;
    }
    while(!s.empty())
    {
        res = res * 10 + s.top();
        s.pop();
    }
    return res;
}

 

接下来的才是正解


既然位数相同,那么我们就知道f(ai,?)时ai的贡献,以及f(?,ai)时ai的贡献,分别计算即可。

code:

#include <cstdio>
#include <stack>

using namespace std;
typedef long long LL;
const int mod = 998244353;
const int MAXN = 100000+7;

int n;
int array[MAXN];

LL func(LL x)
{
    LL res = 0;
    stack<int> s;
    while(x)
    {
        s.push(x%10);
        x /= 10;
    }
    while(!s.empty())
    {
        res = res * 10 + s.top();
        res = res * 10 + s.top();
        s.pop();
        res = res % mod;
    }
    return res * n % mod;
}


int main()
{
    while(scanf("%d", &n) != EOF)
    {
        for(int i=0; i<n; i++)
            scanf("%d", &array[i]);
        LL ans = 0;
        for(int i=0; i<n; i++)
        {
            ans += func(array[i]);
            ans = ans % mod;
        }
        printf("%lld\n", ans);
    }
    


    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值