Educational Codeforces Round 88 (Rated for Div. 2)

时间:2020-05-29
本文章向大家介绍 Educational Codeforces Round 88 (Rated for Div. 2),主要包括 Educational Codeforces Round 88 (Rated for Div. 2)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

题目链接:https://codeforces.com/contest/1359

部分题目讲解:https://www.bilibili.com/video/bv12z411v7WN

代码:

A.Berland Poker

//
//  main.cpp
//  CF
//
//  Created by HanJinyu on 2020/5/15.
//  Copyright © 2020 by HanJinyu. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef double db;
typedef long long ll;
const int maxn=2e5+10;
int main()
{
        #ifdef ONLINE_JUDGE
        #else
            freopen("in.txt","r",stdin);
        #endif
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int  n,m,k;
        scanf("%d%d%d",&n,&m,&k);
        if(n/k>=m)
        {
            printf("%d\n",m);
        }
        else{
            if((m-n/k)>=(k-1))
            {
                int re=(m-n/k)/(k-1);
                if((m-n/k)%(k-1)!=0)
                    re++;
                printf("%d\n",n/k-re);
            }
            else
            {
                printf("%d\n",n/k-1);
            }
        }
       
    }
    
    return 0;
}
View Code

B.New Theatre Square

//-------------------------------------------------
//Created by HanJinyu
//Created Time :三  5/20 12:29:04 2020
//File Name :question.cpp
//-------------------------------------------------

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef double db;
typedef long long ll;
const int maxn = 2e5+10;
int main()
{
    #ifdef ONLINE_JUDGE
    #else
    freopen("in.txt","r",stdin);
    #endif
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m,x,y;
        scanf("%d%d%d%d",&n,&m,&x,&y);
        getchar();
        char str[2000][2000];
        int dian=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                cin>>str[i][j];
                if(str[i][j]=='.')
                    dian++;
                   
            }
        }
        if(2*x<=y||m==1)
        {
            ll res=dian*x;
            printf("%lld\n",res);
            continue;
        }
        else if(n==1&&m==1)
        {
            printf("%d\n",x*dian);
            continue;
        }
        else if(n==1)
        {
            ll res1=0;
            bool used2[maxn]={false};
            for(int j=0;j<m-1;j++)
            {
                if(str[0][j]=='.'&&str[0][j+1]=='.'&&!used2[j])
                {
                    res1+=y;
                    used2[j]=true;
                    used2[j+1]=true;
                }
                if(str[0][j]=='.'&&!used2[j])
                    res1+=x;
            }
            if(str[0][m-1]=='.'&&!used2[m-1])
                res1+=x;
            printf("%lld\n",res1);
            continue;
        }
        else{
        ll res=0;
        for(int i=0;i<n;i++)
        {
            bool used[maxn]={false};
            for(int j=0;j<m-1;j++)
            {
                if(str[i][j]=='.'&&str[i][j+1]=='.'&&!used[j])
                {
                    used[j]=true;
                    used[j+1]=true;
                    res+=y;
                }
                else if(str[i][j]=='.'&&!used[j])
                {
                    res+=x;
                }
            }
            if(str[i][m-1]=='.'&&!used[m-1])
                res+=x;
        }
        printf("%lld\n",res);
        }
        
    }
     return 0;
}
View Code

D.Yet Another Yet Another Task

//
//  main.cpp
//  CF
//
//  Created by HanJinyu on 2020/5/15.
//  Copyright © 2020 by HanJinyu. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef double db;
typedef long long ll;
const int maxn=2e5+10;
int main()
{
        #ifdef ONLINE_JUDGE
        #else
            freopen("in.txt","r",stdin);
        #endif
    int n;
    scanf("%d",&n);
    int a[maxn];
    for(int i=0;i<n;i++)
        scanf("%d",a+i);
    int ans=0;
    for(int i=1;i<=30;i++)
    {
        int cnt=0;
        for(int j=0;j<n;j++)
        {
            if(a[j]>i)
                cnt=0;
            else
            {
                cnt+=a[j];
                if(cnt<0)
                    cnt=0;
                else
                    ans=max(ans,cnt-i);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}
View Code

原文地址:https://www.cnblogs.com/Vampire6/p/12987518.html