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

 

C.Mixing Water

#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;
struct cha{
    int a;
    int b;
    double chaa;
    bool operator<(const cha &a)const
    {
        return (this->chaa)<a.chaa;
    }
};
int main()
{
    #ifdef ONLINE_JUDGE
    #else
        freopen("in.txt","r",stdin);
    #endif
    int t;
    scanf("%d",&t);
    while(t--)
    {
        double h,c,t;
        scanf("%lf%lf%lf",&h,&c,&t);
        if(t>=h)
            printf("1\n");
        else if(t<=(h+c)/2.0)
            printf("2\n");
        else
        {
            int k=(t-h)/(h+c-2*t);
            //k个冷,k+1热,2*k+1
            //k+1冷,k+2热,2*k+3
            double cha1=((k+1)*h+k*c)/(2*k+1);
            double cha2=((k+2)*h+(k+1)*c)/(2*k+3);
            if(abs(cha1-t)<=abs(cha2-t))
                printf("%d\n",2*k+1);
            else
                printf("%d\n",2*k+3);
        }
        
    }
    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

 

posted @ 2020-05-29 15:04  branna  阅读(251)  评论(0编辑  收藏  举报