太简单了,不写题解了。
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);
}