zoukankan      html  css  js  c++  java
  • Codeforces Round #574 (Div. 2) D1. Submarine in the Rybinsk Sea (easy edition) 【计算贡献】

    一、题目

      D1. Submarine in the Rybinsk Sea (easy edition) 

    二、分析

      简单版本的话,因为给定的a的长度都是定的,那么我们就无需去考虑其他的,只用计算ai的值在每个位置的贡献即可。

      因为长度是定的,如果ai在前,那么对所有的a的贡献就是在偶数位的贡献值然后乘以n即可。

      如果ai在后,那么对所有ai的贡献就是在奇数位的贡献值然后乘以n。

      将两种情况合并,其实就是求ai在每个位置下的贡献,然后乘以n。

      时间复杂度是$O(n)$

    三、AC代码

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 typedef long long ll;
     5 const int maxn = 1e5 + 13;
     6 const int mod = 998244353;
     7 int a[maxn], n;
     8 
     9 ll fun(int data)
    10 {
    11     vector<int> vec;
    12     while(data)
    13     {
    14         vec.push_back(data % 10);
    15         data /= 10;
    16     }
    17     reverse(vec.begin(), vec.end());
    18     ll ans = 0;
    19     for(auto itr : vec)
    20     {
    21         ans = ans * 10 + itr;
    22         ans = ans * 10 + itr;
    23         ans %= mod;
    24     }
    25     ans = ans * n % mod;
    26     return ans;
    27 }
    28 
    29 
    30 int main()
    31 {
    32     while(scanf("%d", &n) != EOF)
    33     {
    34         ll ans = 0;
    35         for(int i = 0; i < n; i++)
    36         {
    37             scanf("%d", &a[i]);    
    38         }
    39         ans = fun(a[0]);
    40         for(int j = 1; j < n; j++)
    41         {
    42             ans = (ans + fun(a[j])) % mod;
    43         }
    44         printf("%I64d
    ", ans);
    45     }
    46     return 0;
    47 }
  • 相关阅读:
    C加加学习之路 1——开始
    哈夫曼树C++实现详解
    Linux常用命令
    Accp第二章:基础知识
    第一章Accp 8.0
    泛型集合
    深入C#数据类型
    初始wondows系统
    深入.NET框架
    二至十五章总结
  • 原文地址:https://www.cnblogs.com/dybala21/p/11207472.html
Copyright © 2011-2022 走看看