C/C++教程

Educational Codeforces Round 112 (Rated for Div. 2)

本文主要是介绍Educational Codeforces Round 112 (Rated for Div. 2),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Educational Codeforces Round 112 (Rated for Div. 2)

今天div2又坐牢了。不贴题目了,进原贴看吧。

A. PizzaForces

小于6的特例,大于6的任何偶数可以用6,8,10组合出来。平均时间都是2.5,奇数+1变成偶数,然后乘2.5就是答案。记得long long

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t,n,ans;
    cin>>t;
    while(t--)
    {
        cin>>n;
        if(n<=6)ans=15;
        else
        {
            if(n%2)n++;
            ans=n*2.5; 
        }
        cout<<ans<<endl;
    }
    return 0; 
}

B.Two Tables

比较上下左右的空余空间,水平或竖直移动为最优情况。答案必为整数,后面无脑给0就行(好像不给也够)

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,w,h,x1,x2,y1,y2,a,b,f1,f2;
    int left,right,up,down,p,q; 
    cin>>t;
    while(t--)
    {
        cin>>w>>h>>x1>>y1>>x2>>y2>>a>>b;
        left=x1;
        right=w-x2;
        down=y1;
        up=h-y2;
        if(a>left+right && b>up+down)
            cout<<-1<<endl;
        else if(left>=a || right>=a || up>=b || down>=b)
            cout<<"0.00000000"<<endl;
        else
        {
            f1=f2=0;
            if(a-left<=right)
            {
                p=a-left;
                f1=1;
            }
            if(a-right<=left)
            {
                p=min(p,a-right);
                f1=1;
            }
            if(b-up<=down)
            {
                q=b-up;
                f2=1;
            }
            if(b-down<=up)
            {
                q=min(q,b-down);
                f2=1;
            }
            if(f1&&f2)
            {
                printf("%.8lf\n",(double)min(p,q));
            }
            else if(f1)
                printf("%.8lf\n",(double)p);
            else
                printf("%.8lf\n",(double)q);
        }
    }
    return 0;
}

C. Coin Rows

方向只能往下一次,一直往右。第一行维护后缀和,第二行维护前缀和。对于Bob取score=max(第一行,第二行),对于alice取ans=min(ans,score)。暴力过一遍秒杀

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,ans,pre[2][100005];
    pre[0][0]=pre[1][0]=0;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>pre[1][i];
        pre[0][n]=pre[1][n];
        for(int i=n-1;i>0;i--)
            pre[0][i]=pre[0][i+1]+pre[1][i];
        for(int i=1;i<=n;i++)
        {
            cin>>pre[1][i];
            pre[1][i]+=pre[1][i-1];
        }
        ans=min(pre[0][2],pre[1][n-1]);
        for(int i=2;i<=n;i++)
            ans=min(ans,max(pre[0][i+1],pre[1][i-1]));
        cout<<ans<<endl;
    }
    return 0;
}
这篇关于Educational Codeforces Round 112 (Rated for Div. 2)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!