Codeforces Round #754 (Div. 2) ABC

Problem - A - Codeforces

题目大意:给我们3个数,每次可以选择两分别+1,-1 。

求| a1+a3-a2*2 |  min

input

3
3 4 5
2 2 6
1 6 5

output

0
1
0

%3 就行了,坑点在于余了1只给a2,余了2就a1一个,a2一个。

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<vector>
#include<set>
using namespace std;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        int a[3];
        cin>>a[0]>>a[1]>>a[2];
        sort(a,a+3);
        int sum=a[0]+a[1]+a[2];
        a[0]=sum/3;
        a[1]=sum/3;
        a[2]=sum/3;
        if(sum%3==1) a[2]++;
        else if(sum%3==2) a[1]++,a[2]++;
        //cout<<a[0]<<a[1]<<a[2]<<endl;
        cout<<abs(a[0]+a[2]-2*a[1])<<endl;
    }
    return 0;
}

Problem - B - Codeforces

题目大意:几次才能把一个只有0和1的字符串变成非降序?

input

3
7
0011111
5
10100
6
001000

output

0
1
4 1 3 4 5 
1
3 3 5 6 

一次就够了,把前面需要挪动的1和后面需要挪动的0的位置都存起来就行了

wa了一发存了相同1个数的0的位置,也不知道是怎么想的。。。

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<vector>
#include<set>
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 sum1=0;
        for(int i=0;i<s.size();i++)
            if(s[i]=='1') sum1++;
        if(n==1) cout<<"0"<<endl;
        else
        {
           bool flag=true;
           for(int i=1;i<s.size();i++)
               if(s[i]<s[i-1]) flag=false;
           if(flag==true) cout<<"0"<<endl;
           else
           {
               cout<<"1"<<endl;

               vector<int> vi;
               for(int i=s.size()-1;i>=0;i--)
               {
                   if(s[i]=='1'&&i+sum1<n) vi.push_back(i+1);
                   else if(s[i]=='0'&&i+sum1>=n) vi.push_back(i+1);
                   else continue;
               }
               cout<<vi.size()<<" ";
               sort(vi.begin(),vi.end());
               for(int i=0;i<vi.size();i++)
                   cout<<vi[i]<<" ";
               cout<<endl;
           }
        }
    }
    return 0;
}

Problem - C - Codeforces

题目大意:字符串s只包含a ,b ,c 三种,求a个数严格大于b c 个数的连续区间的长度min。

s从头或从尾巴删起。

input

3
2
aa
5
cbabb
8
cacabccc

output

2
-1
3

 题目说了存在的时候至少为2,那就是aa; 3的时候就有aba   aca; 4的时候有abca   acba   ;

5 没 ; 6 没; 7有abbacca  accabba(这玩意儿太隐蔽了);再大就没了

找不着即为-1

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<vector>
#include<set>
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;
        char s[1001000];
        cin>>s;
        int suma=0,sumb=0,sumc=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='a') suma++;
            else if(s[i]=='b') sumb++;
            else if(s[i]=='c') sumc++;
        }
        //cout<<suma<<" "<<sumb<<" "<<sumc<<endl;
        if(suma==1||suma==0) cout<<"-1"<<endl;
        else
        {
            if(strstr(s,"aa")!=NULL) cout<<"2"<<endl;
            else if(strstr(s,"aca")!=NULL||strstr(s,"aba")!=NULL) cout<<"3"<<endl;
            else if(strstr(s,"abca")!=NULL||strstr(s,"acba")!=NULL) cout<<"4"<<endl;
            else if(strstr(s,"abbacca")!=NULL||strstr(s,"accabba")!=NULL) cout<<"7"<<endl;
            else cout<<"-1"<<endl;
        }
    }
    return 0;
}

先找小的再找大的!!!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Vijurria

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

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

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

打赏作者

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

抵扣说明:

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

余额充值