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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiang_6/article/details/84026931

这些题目挺有意思,起码我都错过,可能这两天精力有点不足,脑子不太够用???

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

猜你喜欢

转载自blog.csdn.net/xiang_6/article/details/84026931