1. 程式人生 > >Educational Codeforces Round 54 (Rated for Div. 2) A B C D E題解

Educational Codeforces Round 54 (Rated for Div. 2) A B C D E題解

這些題目挺有意思,起碼我都錯過,可能這兩天精力有點不足,腦子不太夠用???

 

A題連結:http://codeforces.com/contest/1076/problem/A

題意:給定一個字串,最多可以刪掉一個字元,使得字典序最小;

思路:首先跟原串比較的話,某一個字元大於後面相鄰的字元的話,刪去這個字元,顯然這樣字典序就會變小了,我們也知道,如果有多個這樣的字元對的話,刪掉第一個就ok了,因為字典序是從第一個字元開始比較;  如果所有字元都是非遞減的話,那就只能刪去最後一個字元,這樣字典序是最小的;

我是因為刪完一個字元後,忘了判斷後面的字元,所以wa了一下;=-=

#include<bits/stdc++.h>
using namespace std;
#define out fflush(stdout);
#define fast ios::sync_with_stdio(0),cin.tie(0);
#define FI first
#define SE second
typedef long long ll;
typedef pair<ll,ll> P;
const int maxn = 2e5 + 7;
const int INF = 0x3f3f3f3f;
const ll mod = 998244353;


int main() {fast;
    int n; cin >> n;
    string s;
    cin >> s;
    bool f = 0;
    for(int i = 0; i < s.size()-1; ++i) {
        if(!f && s[i] > s[i+1]) {
            f = 1;
            continue;
        }
        cout << s[i];
    }
    if(f) cout << s[s.size()-1];
    return 0;
}

 

 

B題連結:http://codeforces.com/contest/1076/problem/B

題意:給定一個n,按照題目給定函式執行,問其中“減”的操作運行了幾次,

思路:開始想錯了,步驟2中的最小素因子每次都是當前n的最小素因子,然後只能再找規律,發現如果最小素因子是2的時候,也就是當前2是偶數的時候,剩下的所有步驟,最小素因子都是2,這時候答案加上(n/2)就行了,然後又發現如果這個數最小素因子p不是2的話,那n-p一定是偶數; 所以本題就是最多求一次最小素因子就ok了(我寫麻煩了其實,因為開始打的表2333)

#include<bits/stdc++.h>
using namespace std;
#define out fflush(stdout);
#define fast ios::sync_with_stdio(0),cin.tie(0);
#define FI first
#define SE second
typedef long long ll;
typedef pair<ll,ll> P;


const int maxn = 1e5 + 7;
const int INF = 0x3f3f3f3f;
const ll mod = 998244353;


ll n;

ll f(ll a, ll cnt) {
    if(a == 0) return cnt;
    if(a == 2 || a == 3) return cnt+1;
    for(ll i = 2; i*i <= a; ++i) {
        if(a%i == 0) {
            if(i == 2) {
                return (cnt + a/2LL);
            }
            return f(a-i, cnt+1);
        }
    }
    return cnt+1;
}

int main() {fast;
    cin >> n;
    cout << f(n, 0);
    return 0;
}

 

 

C題連結:http://codeforces.com/contest/1076/problem/C

直接方程求根

#include<bits/stdc++.h>
using namespace std;
#define out fflush(stdout);
#define fast ios::sync_with_stdio(0),cin.tie(0);
#define FI first
#define SE second
typedef long long ll;
typedef pair<ll,ll> P;


const int maxn = 1e5 + 7;
const int INF = 0x3f3f3f3f;
const ll mod = 998244353;

int T;
double d;

int main() {
    cin >> T;
    while(T--) {
        cin >> d;
        double ans = d*d-4*d;
        if(ans < 0) {
            cout << "N" << endl;
        }
        else {
            double a = (d + sqrt(ans)) / 2;
            double b = d - a;
            printf("Y %.9f %.9f\n",a,b);
        }
    }
    return 0;
}

 

 

D題連結:http://codeforces.com/contest/1076/problem/D

詳細題解:https://blog.csdn.net/xiang_6/article/details/84026667

 

E題連結:http://codeforces.com/contest/1076/problem/E

詳細題解:https://blog.csdn.net/xiang_6/article/details/84026790