AtCoder Beginner Contest 103 A-D

太简单了,不写题解了。
A.Task Scheduling Problem

#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if (a<b) swap(a,b);
    if (a<c) swap(a,c);
    if (b<c) swap(b,c);
    printf("%d\n",a-c);
}

B.String Rotation

#include<cstdio>
#include<cstring>
char s[1000],t[1000];
int n;
int main()
{
    int ok;
    scanf("%s%s",s+1,t+1);
    n=strlen(s+1);
    for (int i=1;i<n;i++) s[n+i]=s[i];
    for (int i=1;i<=n;i++)
    {
        ok=1;
        for (int j=1;j<=n;j++)
            if (t[j]!=s[i+j-1])
            {
                ok=0;
                break;
            }
        if (ok)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
}

C.Modulo Summation

#include<cstdio>
int main()
{
    int n,x,ans=0;
    scanf("%d",&n);
    while (n--)
    {
        scanf("%d",&x);
        ans+=x-1;
    }
    printf("%d\n",ans);
}

D. Islands War

#include<cstdio>
#include<algorithm>
using namespace std;
struct interval
{
    int l,r;
    bool operator < (const interval &i) const
    {
        return r<i.r;
    }
}a[200010];
int n,m;
int main()
{
    int now,ans;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;i++) scanf("%d%d",&a[i].l,&a[i].r);
    sort(a+1,a+m+1);
    now=a[1].r;
    ans=1;
    for (int i=2;i<=m;i++)
        if (a[i].l>=now)
        {
            ans++;
            now=a[i].r;
        }
    printf("%d\n",ans);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值