2021-09-26 20:00 ATCoder周赛

2021-09-26 20:00 ATCoder周赛

A - Find Multiple

Problem Statement

Print a number between A and B (inclusive) that is a multiple of C.

If there is no such number, print -1.

Constraints

  • 1≤A≤B≤1000
  • 1≤C≤1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:
A B C

Output

Print the answer.
If there is no number with the desired property, print -1.

AC代码

#include<iostream>

using namespace std;


int main(){

    int f = 0 ;
    int a,b,c;
    cin >>a>>b>>c;
    for(int i = a ; i <= b ; i ++)
    {
        if(i%c==0)
        {
            cout << i << endl ;
            f = 1 ;
            break;
        }
    }
    if(!f) cout << "-1";
}

B - Base K

Problem Statement

You are given integers A and B, in base K.
Print A×B in decimal.

Notes

For base-K representation, see Wikipedia's article on Positional notation.

Constraints

  • 2≤K≤10
  • 1≤A,B≤105
  • A and B are in base-K representation.

Input

Input is given from Standard Input in the following format:

K
A B

Output

Print the answer.

AC代码

#include<iostream>
#include<string>
using namespace std;
 
long long change(string x,long long q){
    long long anss = 0 , ii = 0;
    while(x.size()!=ii)
    {
        anss*=q; 
        anss+=x[ii]-'0';
        ii ++;
    }
    return anss ;
}

int main()
{
    long long r,i=0,ans=0;
    string n,m;
    cin>>r>>n>>m;
    long long a = change(n,r);
    long long b = change(m,r);
    ans = a * b ;
    // cout << a << " "<< b << endl ;
    cout<<ans<<endl;
    return 0;
 }

C - Long Sequence

Problem Statement

We have a sequence of N positive integers: A=(A0,…,AN).
Let B be the concatenation of 10100copies of A.

Consider summing up the terms of B from left to right. When does the sum exceed X for the first time?
In other words, find the minimum integer k such that:

B0+..+Bi..+BN>X

Constraints

  • 1≤N≤105
  • 1≤Ai≤109
  • 1≤X≤1018
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A0...AN
X

Output

Print the answer.

AC代码

#include<iostream>
#include<string>
using namespace std;
 
const long long N = 1e6+10 ;
long long a[N] ;
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n , k = 0 , cnt = 0,q=0; 
    cin >> n ;//3
    for(long long i = 0 ; i < n ; i ++) cin >> a[i] ;// 3 5 2
    long long x ;
    cin >> x ;// 26
    long long sum = 0 ;
    for(long long i = 0 ; i < n ; i ++) sum += a[i];
    // cout << sum << endl ;
    // cout << x/ sum << endl;
    if(sum<x)
    {
        q = x/sum ;
        sum *= q ;
        q=q*n ;
    }
    long long zz = x % sum ;
    // cout << q<<endl;

    for(long long i = 0 ; i < n ; i ++)
    {
        sum += a[i] ;
        if(sum<=x) q++ ; 
        else{
            cout << q + 1 << endl ;
            break ;
        }
    }
    // cout << cnt ;
 }

D - FG operation

Problem Statement

We have a sequence of N integers between 0 and 9 (inclusive): A=(A0....AN), arranged from left to right in this order.
Until the length of the sequence becomes 1, we will repeatedly do the operation F or G below.

Operation F: delete the leftmost two values (let us call them x and y) and then insert (x+y)%10 to the left end.
Operation G: delete the leftmost two values (let us call them x and y) and then insert (x×y)%10 to the left end.

Here, a%b denotes the remainder when a is divided by b.

For each K=0,1,…,9, answer the following question.

Among the 2^(N-1)^possible ways in which we do the operations, how many end up with K being the final value of the sequence?
Since the answer can be enormous, find it modulo 998244353.

Constraints

  • 2≤N≤105
  • 0≤Ai≤9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A1...AN

Output

Print ten lines.
The i-th line should contain the answer for the case K=i−1.

AC代码(1)

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
 
 
signed main(){
  int num = 998244353;
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<int> pre(10,0);
  vector<int> next(10,0);
  pre[a[0]] += 1;
  for (int i = 1; i < n; i++){
    for (int j = 0; j < 10; j++){
      next[(j+a[i])%10] += pre[j];
      next[(j*a[i])%10] += pre[j];
    }
    for (int k = 0; k < 10; k++){
      pre[k] = next[k] % 998244353;
      next[k] = 0;
    }
    // for (int k = 0; k < 9; k++){
    // }
  }
  for (int i = 0; i < 10; i++){
    cout << pre[i] % 998244353 << endl;
  }
  return 0;
}

AC代码(2)

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#define pb push_back
#define mod(x) (x) % MOD
#define LL long long

using namespace std;

const int MOD = 998244353, N = 1e5 + 10;

LL cnt[10];
int n, a[N];


int main() {
    cin >> n;
    for(int i = 0; i < n; i ++ ) cin >> a[i];
    vector<LL> p(10, 0), q(10, 0);
    q[a[0]] = 1;
    for(int i = 1; i < n; i ++ ) {
        for(int j = 0; j < 10; j ++ ) {
            p[j] = q[j] % MOD;
            q[j] = 0;
        }
        for(int j = 0; j < 10; j ++ ) {
            q[(j + a[i]) % 10] =  mod(q[(j + a[i]) % 10] + p[j]);
            q[(j * a[i]) % 10] = mod(q[(j * a[i]) % 10] + p[j]);
        }

    }
    for(int i = 0; i < 10; i ++ ) {
        cout << q[i] % MOD << endl;
    }

    return 0;
}

posted @   ICE_棋  阅读(125)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示