zoukankan      html  css  js  c++  java
  • 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
    ",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/k-re);
                }
                else
                {
                    printf("%d
    ",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
    ",res);
                continue;
            }
            else if(n==1&&m==1)
            {
                printf("%d
    ",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
    ",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
    ",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
    ");
            else if(t<=(h+c)/2.0)
                printf("2
    ");
            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
    ",2*k+1);
                else
                    printf("%d
    ",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
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    【剑指offer】对称的二叉树
    【剑指offer】数组中的逆序对
    【剑指offer】不用加减乘除做加法
    【剑指offer】和为S的连续正数序列
    【剑指offer】删除链表中重复的结点
    【剑指offer】平衡二叉树
    Math.ceil()、Math.floor()和Math.round()
    document.querySelectorAll遍历
    JS选择器querySelector和~All,三个原生选择器
    js 操作select和option常见用法
  • 原文地址:https://www.cnblogs.com/Vampire6/p/12987518.html
Copyright © 2011-2022 走看看