CodeForces Round #555 Div.3

A. Reachable Numbers

代码:

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e9 + 7;
int N;
set<int> s;

int main() {
    scanf("%d", &N);
    while(s.find(N) == s.end()) {
        s.insert(N);
        N += 1;
        while(N % 10 == 0) N /= 10;
    }

    printf("%d\n", (int) s.size());

    return 0;
}
View Code

B. Long Number

代码:

#include <bits/stdc++.h>
using namespace std;

int N;
string s;
int a[10];

int main() {
    scanf("%d", &N);
    cin >> s;
    for(int i = 1; i <= 9; i ++) {
        int x;
        scanf("%d", &x);
        a[i] = x;
    }

    for(int i = 0; i < N; i ++) {
        if(a[s[i] - '0'] > s[i] - '0') {
            for(int j = i; j < N; j ++) {
                if(a[s[j] - '0'] >= s[j] - '0')
                    s[j] = a[s[j] - '0'] + '0';
                else break;
            }
            break;
        }
    }

    cout << s << endl;

    return 0;
}
View Code

C1. Increasing Subsequence (easy version)

代码:

#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int N;
int a[maxn];

int main() {
    scanf("%d", &N);
    for(int i = 0; i < N; i ++)
        scanf("%d", &a[i]);
    string ans = "";

    int l = 0, r = N - 1, pos = 0;
    while(l <= r) {
        if(a[l] < a[r]) {
            if(a[l] > pos) {
                pos = a[l];
                l ++;
                ans += 'L';
            } else if(a[r] > pos) {
                pos = a[r];
                r --;
                ans += 'R';
            } else break;
        } else {
            if(a[r] > pos) {
                pos = a[r];
                r --;
                ans += 'R';
            } else if(a[l] > pos) {
                pos = a[l];
                l ++;
                ans += 'L';
            } else break;
        }
    }

    printf("%d\n", ans.length());
    cout << ans << endl;

    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/zlrrrr/p/10786224.html