2019-07-19  2024-09-15    431 字  1 分钟

Codeforces-C1157 B. Long Number

题意就是对某一个连续子序列进行替换,使得这个序列字典序最大。

Code
  1/**
  2 *    author: Akvicor
  3 *    created: 2019-07-19 15-08-20
  4**/
  5
  6#include <bits/stdc++.h>
  7
  8using namespace std;
  9
 10#ifdef DEBUG
 11string to_string(string s) {
 12	return '"' + s + '"';
 13}
 14
 15string to_string(const char* s) {
 16	return to_string((string) s);
 17}
 18
 19string to_string(bool b) {
 20return (b ? "true" : "false");
 21}
 22
 23template <typename A, typename B>
 24string to_string(pair<A, B> p) {
 25	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
 26}
 27
 28template <typename A>
 29string to_string(A v) {
 30	bool first = true;
 31	string res = "{";
 32	for (const auto &x : v) {
 33		if (!first) {
 34			res += ", ";
 35		}
 36		first = false;
 37		res += to_string(x);
 38	}
 39	res += "}";
 40	return res;
 41}
 42
 43void debug_out() { cerr << endl; }
 44
 45template <typename Head, typename... Tail>
 46void debug_out(Head H, Tail... T) {
 47	cerr << " " << to_string(H);
 48	debug_out(T...);
 49}
 50#endif
 51
 52#ifdef DEBUG
 53#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
 54#else
 55#define debug(...) 17
 56#endif
 57
 58#ifdef DEBUG
 59#define FAST_IO 17
 60#else
 61#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 62#define endl '\n'
 63#endif
 64
 65#define LL long long
 66#define ULL unsigned long long
 67#define rep(i, n) for(int i = 0; i < (n); ++i)
 68#define reep(i, n) for(int i = 0; i <= (n); ++i)
 69#define lop(i, a, n) for(int i = a; i < (n); ++i)
 70#define loop(i, a, n) for(int i = a; i <= (n); ++i)
 71#define ALL(v) (v).begin(), (v).end()
 72#define PB push_back
 73#define VI vector<int>
 74#define PII pair<int,int>
 75#define FI first
 76#define SE second
 77#define SZ(x) ((int)(x).size())
 78
 79const double EPS = 1e-6;
 80const double PI = acos(-1.0);
 81const int INF = 0x3f3f3f3f;
 82const LL LINF = 0x7f7f7f7f7f7f7f7f;
 83const int MAXN = (int)1e6 + 10;
 84const int MOD = (int)1e9 + 7;
 85
 86
 87
 88int main(){
 89	FAST_IO;
 90
 91	int n;
 92	while(cin >> n){
 93		string s;
 94		cin >> s;
 95		string conv;
 96		conv.push_back('0');
 97		int a;
 98		rep(i, 9){
 99			cin >> a;
100			conv.push_back(a+'0');
101		}
102		for(int i = 0; i < s.length(); ++i){
103			if(s[i] < conv[s[i]-'0']){
104				while(s[i] < conv[s[i]-'0']){
105					s[i] = conv[s[i]-'0'];
106					++i;
107				}
108				break;
109			}
110		}
111		cout << s << endl;
112	}
113
114	return 0;
115}

除另有声明外本博客文章均采用 知识共享 (Creative Commons) 署名 4.0 国际许可协议 进行许可转载请注明原作者与文章出处