题目链接: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;
}