熬夜打比赛真有趣
竟然上分了真有趣
Your room: 233
有可能更D
A.
题意:有三个人在数轴上\(a,b,c\)的位置,每秒其中一个能移动1个单位长度,求他们两两之间距离至少为\(d\)的时间。
分析:直接分类讨论,显然挪左右两个才是最好的
#include<bits/stdc++.h>
using namespace std;
int a[10],d;
int main()
{
cin>>a[1]>>a[2]>>a[3]>>d;
sort(a+1,a+4);
if (a[2]-a[1]<d)
{
if (a[3]-a[2]<d)
{
cout<<d-(a[3]-a[2]) + d-(a[2]-a[1]);
}
else
cout<<d-(a[2]-a[1]);
}
else
{
if (a[3]-a[2]<d)
{
cout<<d-(a[3]-a[2]);
}
else cout<<0;
}
return 0;
}
B:
题意:有两个字符串。求一个字符串删掉某些重复字母后是否成为另一个字符串。
分析:直接模拟即可,注意重复字母的情况。
#include<bits/stdc++.h>
using namespace std;
int n,len,len1;string st,st1;
bool check()
{
int js=0,ks=0;
for (int j=0,k=0;j<len||k<len1;j++)
{
js=0;ks=0;
if (st[j]!=st1[k]||(j==len&&k!=len1)||(j!=len&&k==len1))
{
return false;
}
while (st1[k]==st1[k+1]&&k<len1-1) k++,ks++;
while (st[j]==st[j+1]&&j<len-1) j++,js++;
if (js>ks) return false;
k++;
}
return true;
}
int main()
{
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>st;
cin>>st1;
len=st.size(),len1=st1.size();
if (check()) cout<<"YES\n";else cout<<"NO\n";
}
return 0;
}
C1
Codeforces Round #568 (Div. 2) 题解(A,B,C)
原文:https://www.cnblogs.com/fmj123/p/11062144.html