Educational Codeforces Round 114 (Rated for Div. 2) A/B/C/...

题单

Dashboard - Educational Codeforces Round 114 (Rated for Div. 2) - Codeforces


A

题意:

给一个数n,打印n个2n长度的字符串,' ( ' 的数目时刻比 ' ) ' 的数目多或相等。

思路:

依次交换下标对应符号。

swap(n,n+1);

swap(n-1,n);

swap(n-2,n-1);

swap(n-3,n-2);

...

swap(1,2);

题解:

#include <bits/stdc++.h>
#define bbn 200005
#define maxint 2147483647
#define maxLLint 9223372036854775807
#define mod 1000000007 //1e9+7
const double eps=1e-7;
typedef  long long int  LL;
using namespace std;
int t,n;
void print(char c[])
{
    for(int i=1; i<=2*n; i++)
    {
        cout<<c[i];
    }
    cout<<endl;
}
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n;
        char c[101]= {};
        for(int i=1; i<=n; i++)
        {
            c[i]='(';
        }
        for(int i=n+1; i<=2*n; i++)
        {
            c[i]=')';
        }
        for(int i=1; i<=n; i++)
        {
            print(c);
            swap(c[n-i+1],c[n-i+2]);
        }
    }
}

B

题意:

判断a个‘a’,b个‘b’,c个‘c’能否组成正好有m个相同连续序列(a[i]=a[i+1]就能算一个)。

思路:

求边界范围即可。

于是画图推公式。

最大数目:

max_num=a-1+b-1+c-1

最小数目:

min_num=max-1-mid-min

题解:

#include <bits/stdc++.h>
#define bbn 200005
#define maxint 2147483647
#define maxLLint 9223372036854775807
#define mod 1000000007 //1e9+7
const double eps=1e-7;
typedef  long long int  LL;
using namespace std;
int t,n,a[4],m;
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>a[1]>>a[2]>>a[3]>>m;
        sort(a+1,a+4);
        int maxn=a[3]-1+a[2]-1+a[1]-1;
        int minn=a[3]-1-a[2]-a[1];
        if(m<minn||maxn<m)
        {
            cout<<"NO"<<endl;
        }
        else
        {
            cout<<"YES"<<endl;
        }

    }
}

C

题意:

给出n个勇者及勇者的力量数值。

给出m条恶龙及恶龙的防御力,攻击力。

每条恶龙都是一个独立事件。一个硬币可以提高一个勇者一点数值的力量。讨伐恶龙时,派出一个力量大于等于恶龙防御的勇者,剩余的勇者们力量和大于等于恶龙攻击力。让花费的硬币最少。

思路:

先从小到大排序勇者的力量。

STL二分 找第一个大于等于恶龙防御力的勇者,考虑越界情况并计算花费。

题解:

#include <bits/stdc++.h>
#define bbn 200005
#define maxint 2147483647
#define maxLLint 9223372036854775807
#define mod 1000000007 //1e9+7
const double eps=1e-7;
typedef  long long int  LL;
using namespace std;
LL n,m,total;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    cin>>n;
    vector<LL> h(n);
    for(LL i=0; i<n; i++)
    {
        cin>>h[i];
        total += h[i];
    }
    sort(h.begin(), h.end());
 
    cin>>m;
    while(m--)
    {
        LL d,p,minn=maxLLint;
        cin>>d>>p;
        LL pos=lower_bound(h.begin(), h.end(), d)-h.begin();
        if(pos>0)
        {
            minn=min(minn,d-h[pos-1]+max(p-total+h[pos-1],(LL)0));
        }
        if(pos<n)
        {
            minn=min(minn,max(p-total+h[pos],(LL)0));
        }
        cout<<minn<<"\n";
    }
    return 0;
}

总结:

这场特殊原因没打...


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值