Contest2675 - 2021ACM俱乐部后备营个人训练赛第13场
蒻蒻发言:上一场比赛在车上,随便水了三个就撤了,其实就是晕车,所以没有题解,嘿嘿嘿
问题 C: 乒乓球
Solution
惯例:在怎样读入多行的时候卡了一下,一开始用string和getline做的,但是发现它还是不能读多行,没想明白,换的char逐个读入做的
简单统计,两次循环,特别注意提示的话——兵乓球比赛知识:假设11分制下,如果比值达到10:10以后,需要分值相差 2 分以上才算胜利, 比如14:12。属于其中一个判断条件
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
char x,s[1000000];
int a=0,b=0,n=0;
while(1)
{
cin>>x;
if(x=='E')
break;
if(x=='W' || x=='L')
s[++n]=x;
}
for(int i=1;i<=n;++i)
{
if(s[i]=='W')
++a;
if(s[i]=='L')
++b;
if((a>=11 || b>=11) && abs(a-b)>1)
{
cout<<a<<":"<<b<<endl;
a=0;
b=0;
}
}
cout<<a<<":"<<b<<endl;
a=0;
b=0;
cout<<endl;
for(int i=1;i<=n;++i)
{
if(s[i]=='W')
++a;
if(s[i]=='L')
++b;
if((a>=21 || b>=21) && abs(a-b)>1){
cout<<a<<":"<<b<<endl;
a=0;
b=0;
}
}
cout<<a<<":"<<b;
return 0;
}
问题 D: 栈
Solution
栈的简单入门题,可以用卡特兰数(Catalan)做,不会的去看它——卡特兰数(Catalan)及其应用
Code
#include <bits/stdc++.h>
using namespace std;
int Catalan(int n)
{
if(n<=1)
return 1 ;
int h[n+1];
h[0]=h[1]=1;
for(int i=2;i<=n;++i)
{
h[i]=0;
for(int j=0;j<i;++j)
{
h[i] += (h[j]*h[i-1-j]);
}
}
int ans = h[n];
return ans;
}
int main()
{
int n;
cin>>n;
cout<<Catalan(n);
return 0;
}
问题 E: 节水活动
Solution
简单求和
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x,y;
cin>>n;
long long ans=0;
while(n--)
{
cin>>x>>y;
ans += x*y;
}
cout<<ans;
return 0;
}
问题 F: 远足活动
Solution
八个字——能上就上,不能上就下。注意一下:“在N天,他必须回到大本营”
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b;
int s=0;
cin>>n>>a>>b;
for(int i=1;i<=n;++i)
{
if(i*a>=b*(n-i) && a*i-b*(n-i)<=a)
s = b*(n-i);
if(i*a<=b*(n-i) && b*(n-i)-a*i<=b)
s = a*i;
}
cout<<s;
return 0;
}
问题 G: 交替01串
Solution
简单统计,由于’0’,‘1’,也算一个01串,所以输出结果加一
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
char c;
cin>>s;
int count=0,maxc=0;
for(int i=0;i<s.length()-1;++i)
{
c=s[i];
if(c!=s[i+1])
{
++count;
maxc = max(maxc,count);
}
else
count=0;
}
cout<<maxc+1;
return 0;
}
问题 H: 回文数列
Solution
比较前后的数是否相同,相同则继续比较下一组前后;若不相同且前面的数小于后面,则前面的数相加;若不相同且前面的数大于后面,则后面的数相加,每次相加时统计次数即可
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long a[1000000];
long long n,s,t,i;
cin>>n;
s=1;
t=n;
long long count=0;
for(i=1;i<=n;++i){
cin>>a[i];
}
while(s<t)
{
if(a[s]==a[t])
{
s = s+1;
t = t-1;
}
else if(a[s]<a[t])
{
a[s+1] = a[s]+a[s+1];
s = s+1;
count = count+1;
}
else
{
a[t-1] = a[t]+a[t-1];
t = t-1;
count = count+1;
}
}
cout<<count;
}
问题 I: Tak and Hotels I
Solution
简单求和,简单英文题面
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n,k,x,y;
cin>>n>>k>>x>>y;
long long ans=0;
if(n<k)
ans = n*x;
else
ans = k*x+(n-k)*y;
cout<<ans;
return 0;
}
问题 J: Beautiful Strings I
Solution
统计字符,均为偶数则"Yes",否则"No",注意一下大小写(别问我为啥要你们注意,问就是憨憨本人WA过)
Code
#include <bits/stdc++.h>
using namespace std;
int a[26]={
0};
int main()
{
string s;
cin>>s;
for(int i=0;i<s.length();++i)
++a[s[i]-'a'+0];
for(int i=0;i<26;++i)
{
if(a[i]%2!=0)
{
cout<<"No";
return 0;
}
}
cout<<"Yes";
return 0;
}