Dang_Quan_10_Tin

Sắp xếp THT Bảng B 2021

Jul 22nd, 2020 (edited)
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5. using ll = long long;
  6.  
  7. constexpr int N = 1e5 + 5;
  8. constexpr int Inf = 999999999;
  9.  
  10. int n, s[N], p[N];
  11. int a, b;
  12.  
  13. void Read()
  14. {
  15.     cin >> a >> b;
  16.  
  17.     for(int i = a; i <= b; ++i)
  18.         s[++n] = i;
  19. }
  20.  
  21. // Compare x and y
  22. bool com(int x, int y) {
  23.     string a, b;
  24.     while(x) {
  25.         a.push_back(char(x % 10 + '0'));
  26.         x /= 10;
  27.     }
  28.     while(y) {
  29.         b.push_back(char(y % 10 + '0'));
  30.         y /= 10;
  31.     }
  32.  
  33.     reverse(a.begin(), a.end());
  34.     reverse(b.begin(), b.end());
  35.  
  36.     return a < b;
  37. }
  38.  
  39. void Solve() {
  40.     fill_n(p, N, Inf);
  41.     p[0] = 0;
  42.     int ans(0);
  43.  
  44.     for(int i = 1; i <= n; ++i) {
  45.         int j = lower_bound(p + 1, p + n + 1, s[i], com) - p;
  46.  
  47.         ans = max(ans, j);
  48.         if(com(s[i], p[j]))
  49.             p[j] = s[i];
  50.     }
  51.  
  52.     cout << n - ans;
  53. }
  54.  
  55. int main ()
  56. {
  57.     ios_base::sync_with_stdio(false);
  58.     cin.tie(NULL);
  59.     cout.tie(NULL);
  60.  
  61.     Read();
  62.     Solve();
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment