1. 程式人生 > >【Educational Codeforces Round 54 (Rated for Div. 2) 】

【Educational Codeforces Round 54 (Rated for Div. 2) 】

前言

e d u

c f
這場edu還算打的比較順利,好久沒打cf的我前期竟然比以前還穩

穩地莫名其妙,果然第四題栽住了
d i j 看到題之後自己腦補了一顆dij跑出來的樹(賽後才知道這叫最短路樹)
好久不敲圖論自己上去硬莽,寫了一個多小時才艱難通過
導致第五題沒時間看,可能看了場上也敲不出來
r a t i n g + 12 , c o d e f o r c e s rating+12,距離上紫還有一些時日,codeforces太好玩了


A. Diverse Substring

題意

n 使 從一個長度為n的字串中移除一個字元使整個字串字典序變得最小
1 < = n < = 2 1 0 5 1<=n<=2*10^5

做法

如果可以讓字典序變小,而且保證最小,肯定是優先移除前面的,不然移除後面的字典序還是不變
使 所以就找到第一個移除之後能使字典序變小的字元一處就可以
使 什麼樣的字元移除後能使字典序變小呢
s t r [ i ] > s t r [ i + 1 ] s t r [ i ] 使 思考一下就是str[i]>str[i+1]的時候,移除str[i]會使字典序變小

坑點

注意原字串一直遞增時刪掉最後一個最優

程式碼

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 2e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

char str[maxn];
int a[maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int len;
    scanf("%d%s",&len,str);
    for(int i=0;i<len-1;i++)
    {
        if(str[i]>str[i+1])
        {
            for(int j=0;j<i;j++) printf("%c",str[j]);
            for(int j=i+1;j<len;j++) printf("%c",str[j]);
            return 0;
        }
    }
    for(int i=0;i<len-1;i++)
    {
         printf("%c",str[i]);
    }
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}

B. Divisor Subtraction

題意

n n 不斷執行從n中減去n的最小質因子的過程
求這個過程會被執行多少次
2 &lt; = n &lt; = 1 0 1 0 2&lt;=n&lt;=10^10

做法

n 2 n / 2 若n為偶數,毫無疑問每次都-2,次數就是n/2
n n 若n為奇數,n一定存在一個質因子,而這個質因子一定是奇數