Codeforces Round #780 (Div. 3) ABCF1

Problem - A - Codeforces

题目大意:有a个1元硬币,b个2元硬币,问不能组成的最小数字是谁?

 input

5
1 1
4 0
0 2
0 0
2314 2374

output

4
5
1
1
7063
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<queue>
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        if(a==0) cout<<"1"<<endl;
        else if(b==1&&a<1) cout<<"0"<<endl;
        else cout<<a+b*2+1<<endl;
    }
    return 0;
}

Problem - B - Codeforces

题目大意:n种糖果,吃多了会腻,所以我想连续两天不吃同一种,问能否做到?

input

6
2
2 3
1
2
5
1 6 2 4 3
4
2 2 2 1
3
1 1000000000 999999999
1
1

output

YES
NO
NO
YES
YES
YES
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<queue>
using namespace std;
typedef long long LL;
LL a[200200];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL t;
    cin>>t;
    while(t--)
    {
        LL n;
        cin>>n;
        for(LL i=1;i<=n;i++)
            cin>>a[i];
        if(n==1)
        {
            if(a[1]!=1) cout<<"NO"<<endl;
            else cout<<"YES"<<endl;
        }
        else
        {
            sort(a+1,a+1+n);
            reverse(a+1,a+1+n);
            if(a[1]-a[2]>=2) cout<<"NO"<<endl;
            else cout<<"YES"<<endl;
        }
    }
    return 0;
}

Problem - C - Codeforces

题目大意:定义一个偶数字符串需要同时满足以下两个要求:1.他的个数必须是偶数个,2.他必须在奇数的坐标下a[i]==a[i+1]。

给我们一些字符串,问我们改造成偶数字符串最少需要删掉几个字符?(可以随便位置上删去)

input

6
aabbdabdccc
zyx
aaababbb
aabbcc
oaoaaaoo
bmefbmuyw

output

3
3
2
0
2
7

被dp误导了好久...(dp不熟练呜呜呜)

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        map<char,int> mp;
        int sum=s.size();
        for(int i=0;i<s.size();i++)
        {
            mp[s[i]]++;
            if(mp[s[i]]==2)
            {
                sum-=2;
                mp.clear();
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}

Problem - F1 - Codeforces

题目大意:一个字符串内如果是➕和➖的个数都相等的话,那么就说他们是平衡的。给定一个字符串,问其中的子字符串有几个是平衡的?

input

5
3
+-+
5
-+---
4
----
7
--+---+
6
+++---

output

2
4
2
7
4 
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int sum=0;
        for(int i=0;i<s.size();i++)
        {
            int jian=0,jia=0;
            for(int j=i;j<s.size();j++)
            {
                if(s[j]=='+') jia++;
                else jian++;
                if(jian>=jia&&(jian-jia)%3==0)
                    sum++;
                //+-   ---  +---- ...... 
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Vijurria

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值