AtCoder Beginner Contest 189 Problem Solving Report

Title link: https://atcoder.jp/contests/abc189/tasks

A - Slot

Topic

Input a string containing only three characters, if they are all the same, output "Won", otherwise output "Lost"

Ideas

Water problem.

ac code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    string a; cin >> a;
    if(a[0] == a[1] && a[0] == a[2]) puts("Won");
    else puts("Lost");
    return 0;
}

B - Alcoholic

Topic

drink. There are n bottles of wine, each bottle is aiml, when the alcohol concentration is bi, Takahashi's alcohol volume is m, and then he has to drink in order, and ask you which bottle he will be drunk when he drinks, if all the alcohol is finished and he is not drunk (His stomach is big enough to hold everything!), then -1 is output.

Ideas

simulation. Calculate the alcohol content ai*bi of the bottleless wine, and then drink sequentially until the alcohol content exceeds m*100.

ac code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int a[maxn];
int main(){
    int n, m;
    cin >> n >> m;
    m *= 100;
    for(int i = 1; i <= n; i ++){
        int x, y;
        cin >> x >> y;
        a[i] = x * y;
    }
    int ans = -1, id = 1;
    while(id <= n){
        m -= a[id];
        ans = id ++;
        if(m < 0) break;
    }
    if(m >= 0) ans = -1;
    cout << ans << endl;
    return 0;
}

C - Mandarin Orange

Topic

n numbers, the operation (l, r, x) represents the numbers in the interval [l, r], and each number is greater than or equal to x, the value represented by s = x * (r-l + 1), and the conditions are satisfied The maximum value of s

Ideas

violence. For each position, the number is spread left and right until the boundary value is less than this value, and then the maximum value is updated.

ac code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e4 + 5;
int a[maxn];
int main(){
    int n; cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 1; i <= n; i ++){
        int id = i + 1, l = i, r = i; //l,r分别代表扩展左右边界
        while(id <= n && a[i] <= a[id]){
            r = id ++;
        }
        id = i - 1;
        while(id >= 1 && a[i] <= a[id]) {
            l = id --;
        }
        ans = max(ans, a[i] * (r - l + 1)); //(l, r, x) 这里的a[i]就作为x, 区间长度是r - l + 1,所以代表的值就是a[i] * (r - l + 1)
    }
    cout << ans << endl;
    return 0;
}

D - Logical Expression

Topic

Give you n strings, either "AND" or "OR", which respectively represent the AND operation and the OR operation in the bit operation, and then let you construct a length of n+1 that only contains "False" and "True" The sequence of which makes the final result of the expression consisting of n strings is True. Ask you how many such sequences are there.

For example, the two strings "AND", "OR" of the sample, then the constructed sequence can be {True, False, True}, because True & False | True = True. There are 5 such sequences, then output 5

Ideas

It is a bit like the recursive formula of dp. Suppose that the number of True after the operation from the first position to the i-1th position is a1, which is initialized to 1, and the number of False is initialized to a2.

If the operation of the i-th position is AND, then if the result of the operation is True, then only 1&1, that is to say, the number of the operation results of the i-th position is True is a1; otherwise, if the operation result is False, then it can be 1&0 ,0&1,0&0, that is to say, the number of False results to the i-th position is a1+a2+a2.

In the same way, if the operation at the i-th position is OR, and the result of the operation is True, then it can be 1|1, 1|0, 0|1, which means that the number of the operation results at the i-th position is True is a1+a1+a2; Otherwise, if the result of the operation is False, then it can only be 0|0, which means that the number of positions where the result of the operation is False is a2.

The final result is the recursive a1.

ac code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e4 + 5;
string a[66];
int main(){
    ll ans = 0;
    int n; cin >> n;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    ll a1 = 1, a2 = 1, t1, t2;
    for(int i = 1; i <= n; i ++){
        if(a[i] == "OR"){
            t1 = a1 * 2 + a2;
            t2 = a2;
        }else{
            t1 = a1;
            t2 = a1 + a2 * 2;
        }
        a1 = t1, a2 = t2;
    }
    cout << a1 << endl;
    return 0;
}

Question E is to be completed. Although it was processed offline during the game, it was still t.

Guess you like

Origin blog.csdn.net/weixin_43911947/article/details/113063339
Recommended