AtCoder Beginner Contest 135(A-D)

A:简单的判断输出

#include 
using namespace std;
typedef long long ll;
const int maxn = (int)1e3 +10;

int main()
{
    ll a, b;
    cin>>a>>b;
    if((a+b)%2 == 0)
        cout<<(a+b)/2;
    else
        cout<<"IMPOSSIBLE"<

B:用pos记录一下不相等个数

#include 
using namespace std;
typedef long long ll;
const int maxn = (int)1e3 +10;

int main()
{
    int n;
    cin>>n;
    int arr[60];
    int pos = 0;
    for(int i = 1; i <= n; i++)
    {
        cin>>arr[i];
        if(arr[i] != i) pos++;
    }
    if(pos == 0 || pos == 2) cout<<"YES"<

C:简单贪心

#include 
using namespace std;
typedef long long ll;
const int maxn = (int)1e5 +10;

int arr[maxn];
int brr[maxn];

int main()
{
    int n;
    cin>>n;
    ll ans = 0;
    for(int i = 0; i <= n; i++)
    {
        cin>>arr[i];
    }
    for(int i = 0; i < n; i++)
    {
        cin>>brr[i];
    }
    for(int i = 0; i < n; i++)
    {
        if(brr[i]>arr[i])
        {
            ans+=arr[i];
            brr[i]-=arr[i];
            if(brr[i]>=arr[i+1])
            {
                ans += arr[i+1];
                arr[i+1] = 0;
            }
            else
            {
                ans += brr[i];
                arr[i+1] -= brr[i];
            }
        }
        else
        {
            ans += brr[i];
        }
    }
    cout<

                                          Digits Parade

题目链接:ABC 135 D

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 400400 points

 

Problem Statement

Given is a string SS . Each character in SS is either a digit (0, ..., 9) or ?.

Among the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 55 when divided by 1313 ? An integer may begin with 00 .

Since the answer can be enormous, print the count modulo 109+7109+7 .

Constraints

  • SS is a string consisting of digits (0, ..., 9) and ?.
  • 1≤|S|≤1051≤|S|≤105

Input

Input is given from Standard Input in the following format:

SS

Output

Print the number of integers satisfying the condition, modulo 109+7109+7 .


Sample Input 1 Copy

??2??5

Sample Output 1 Copy

768

For example, 482305,002865,482305,002865, and 972665972665 satisfy the condition.


Sample Input 2 Copy

?44

Sample Output 2 Copy

1

Only 044 satisfies the condition.


Sample Input 3 Copy

7?4

Sample Output 3 Copy

0

We may not be able to produce an integer satisfying the condition.


Sample Input 4 Copy

?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???

Sample Output 4 Copy

153716888

       

题的大意就是一个最大1e5的字符串,有‘0’~‘9’和‘?’,问有多少数可以mod13 = 5,最后把答案mod 1e9 + 7。

这道题中设计到了同余定理的应用,有兴趣的同学可以查看这篇博客https://blog.csdn.net/hpu2022/article/details/81190214

 

#include 
using namespace std;
typedef long long ll;
const int maxn = (int)1e5 +10;
const int MOD = 1e9 + 7;

ll qpow(ll a, ll n)
{
    ll re = 1;
    while(n)
    {
        if(a&1) re = (re*a)%13;
        n = n>>1;
        a = (a*a)%13;
    }
    return re;

}

int mod[maxn][10];//第i位值为j的数对13取余的值
ll dp[maxn][20];//第i位对j取余的个数
void init()
{
    ll num = 1;
    for(int i = 1; i < maxn; i++)
    {
        for(int j = 0; j < 10; j++)
            mod[i][j] = j * num % 13;
        num = num * 10 % 13;
    }
}
int main()
{
//    while(1)
//    {
        string s;
        cin>>s;
        reverse(s.begin(),s.end());
        init();
        memset(dp, 0, sizeof dp);
        dp[0][0] = 1;
        for(int i = 0; i < s.length(); i++)
        {
            if(isdigit(s[i]))
            {
                for(int j = 0; j < 13; j++)
                {
                    dp[i+1][(mod[i+1][s[i] - '0'] + j)%13] = dp[i][j];
                }
            }
            else
            {
                for(int j = 0; j < 10; j++)
                {
                    for(int k = 0; k < 13; k++)
                    {
                        ll x = (mod[i+1][j] + k)%13;
                        dp[i+1][x] = (dp[i+1][x] +dp[i][k])%MOD;
                    }
                }
            }
        }
        cout<

 

你可能感兴趣的:(AtCoder)