Educational Codeforces Round 90 (Rated for Div. 2)题解

A. Donut Shops

  • 题目传送门
  • 水题,就用a * b和c比一下大小就行了,要求买第一种饼干便宜的情况就假设只买一块,比较a和c的大小,求买第二种便宜就比较 a * b和c比大小就行了
#include
using namespace std;
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll t,a,b,c;
 
 
int main()
{
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
        cin>>a>>b>>c;
        ll a1=0,a2=0;
        if(c>a){
            cout<<"1"<<" ";
        }else{
            cout<<"-1"<<" ";
        }
        ll tmp=a*b;
        if(tmp>c){
            cout<

B. 01 Game

  • 题目传送门
  • 之前做过一个类似的,结果被自己误导了wa了一发,想复杂了,其实就记录一下0和1的个数然后看较小者能不能被2整除就行了,emmmm其实可以证明,1和0数量少的那一个总会被消完。
#include
using namespace std;
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int t;
string s;
 
 
int main()
{
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
        cin>>s;
        int ans=0;
        int a0=0,a1=0;
        for(int i=0;i

C. Pluses and Minuses

  • 题目传送门

  • 这个其实很简单就把cur=0开始,把每个符号的cur都走一遍,比如

  •   --+-
    
  • 对应 -1 -2 -1 -2
    对应的为cur数组(代码中就是r数组)
    那么就从-1开始走,标记ans=0,如果遇到比cur[i]更小的,那么ans就加上这个cur的下标。最后再加一个整个数组的长度

  • 这题不开long long 会爆int,wa on test7,我就wa了一发(彩笔落泪

#include
using namespace std;
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll t;
string s;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 10;
ll r[maxn];
 
int main()
{
    ios::sync_with_stdio(false);
    cin >> t;
    while (t--) {
        cin >> s;
        //int rec=0;
        //int a=0,r=0;
        if (s[0] == '+') r[0] = 1;
        else r[0] = -1;
        ll len = s.size();
        for (ll i = 1; i < s.size(); ++i) {
            r[i] = s[i] == '+' ? r[i - 1] + 1 : r[i - 1] - 1;
        }
        //r[len] = -0x3f3f3f3f;
        ll rec = 0;
        ll ans = 0;
        for (ll i = 0; i <= len; ++i) {
            if (i == len) {
                ans += len;
                break;
            }
            if (r[i] < rec) {
                rec = r[i];
                ans += i + 1;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}

D. Maximum Sum on Even Positions

  • 题目传送门

  • 这个题比赛的时候想假了,最后还是看的dalao的(pxy,yyds!)下来之后其实仔细想想,这题是以前做过的一道题,只是这里把奇偶分开考虑了而已,我真的太菜了,这题其实只要发现只有偶数长度的子串翻转才有效,奇数长度的反转对结果没影响,然后再简单想想就有了(我真的太菜了,落泪

#include
using namespace std;
const int maxn = 2e5 + 10;
typedef long long ll;
ll t, n, a[maxn], r1[maxn], r2[maxn];
 
int main()
{
    ios::sync_with_stdio(false);
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 0; i < n; ++i) cin >> a[i];
        int f = 1;
        for (int i = 0; i < n - 1; i += 2) {
            r1[f] = a[i + 1] - a[i];
            f++;
        }
        int f1 = 1;
        for (int i = 2; i < n; i += 2) {
            r2[f1] = a[i - 1] - a[i];
            f1++;
        }
        ll sum = 0;
        for (int i = 0; i < n; i += 2) sum += a[i];
        ll tmp = 0, now = 0;
        for (int i = 0; i < f; ++i) {
            now += r1[i];
            if (now <= 0) now = 0;
            tmp = max(tmp, now);
        }
        ll tmp1 = 0; now = 0;
        for (int i = 0; i < f1; ++i) {
            now += r2[i];
            if (now <= 0) now = 0;
            tmp1 = max(tmp1, now);
        }
        sum = max(sum + tmp1, sum + tmp);
        cout << sum << "\n";
    }
    return 0;
}

顺便把大佬的代码也放上来叭(pxy,yyds!

#include
using namespace std;
typedef long long ll;
int s[200010],d[200010];
 
long long MaxSubseqSum4( int A[], int N ) {
    long long ThisSum, MaxSum, i;
    
    ThisSum = MaxSum = 0;
    for( i = 1; i < N; i+=2 ) {
            ThisSum += (A[i]);
            if( ThisSum > MaxSum ){
                MaxSum = ThisSum;
            }
            else if( ThisSum < 0 ) 
                ThisSum = 0;
    }
    ThisSum=0;
    for( i = 2; i < N; i+=2 ) {
        ThisSum -= (A[i]);
        if( ThisSum > MaxSum )
            MaxSum = ThisSum;
        else if( ThisSum < 0 )
            ThisSum = 0;
    }
    return MaxSum;  
}
 
int main(){
    int a,b,c,t,x,y;
    long long rzt,xxt,max;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&a);
        rzt=0;
        for(int l1=0;l1
  • 太菜了我,被自己菜哭,菜到睡不着,所以起来顺手把前四题的题解写了,ef明天睡醒了起来补

你可能感兴趣的:(codeforces)