Educational Codeforces Round 39 (Rated for Div. 2)

传送门

A. Partition

题意:把n个数分为{B},{C},然后求B-C的最大值。
思路:就是求所有数字的绝对值的和。

#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
using namespace std;
int main ()
{
    //yyy_3y
    //freopen("1.in","r",stdin);
    int n; scanf("%d",&n);
    LL sum=0;
    for(int i=1;i<=n;i++){
        int x; scanf("%d",&x);
        if(x<0) sum= sum-x;
        else sum+=x;
    }
    printf("%lld\n",sum);
    return 0;
}

B. Weird Subtraction Process

题意:
如果a  = 0或b  = 0,则结束该过程。否则,请转到步骤2 ;
如果  a≥2· b,则 a= a - 2· b,并重复步骤1。否则,请转到步骤3 ;
如果b  ≥2· a,b=b - 2·a,并重复步骤1。否则,结束该过程。

思路:模拟。

#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
using namespace std;
int main ()
{
    //yyy_3y
    //freopen("1.in","r",stdin);
    LL a,b; scanf("%lld%lld",&a,&b);
    while(true){
        if(a==0 || b==0) break;
        if(a>=2*b){
            a%=(2*b);
            continue;
        }
        else {
            if(b>=2*a) b%=(2*a);
            else break;
        }
    }
    printf("%lld %lld\n",a,b);
    return 0;
}

C. String Transformation

题意:字符串转换。
在一次移动中,您可以将字符串的任何字符以字母顺序替换为下一个字符(a将被替换为b,s将替换为t等)。您不能用任何其他字母替换字母z。
问你能否把给出的串变成”abcdefghijklmnopqrstuvwxyz“
思路:枚举替换。

#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
using namespace std;
string str="abcdefghijklmnopqrstuvwxyz";
string sc;

int main ()
{
    //yyy_3y
    //freopen("1.in","r",stdin);
    cin >> sc;
    int cnt=0;
    for(int i=0;i<sc.size();i++){
        if(sc[i]<=str[cnt]){
            sc[i]=str[cnt];
            cnt++;
        }
        if(cnt==26) break;
    }
    if(cnt==26) cout<<sc<<endl;
    else cout<<"-1"<<endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值