第一次比赛总结

第一次比赛总结

1.做题情况


flowers flower lucky abc total(总分) 名次
30 100 80 10 230 3

2.赛中表现

flowers 考虑到c<=d,后将样例过后便没管,flower 直接将暴力写出,lucky 快速写完 ,abc第一个样例过后,第二个样例错误后 更新做法 将第二个样例k.o

3.比赛题解

flowers

简单到上代码

#include <bits/stdc++.h>
using namespace std;
int main() {
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	b+=a/3;
	c+=b/3;
	if(c<=d)
	{
		cout<<c;
		return 0;
	}
	else
	{
		c-=d;
		d+=c/4;
	}
	cout<<d;
	return 0;
}

flower

从2遍历到n-1

判断

ans++

输出

结束

ACCODE

#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=2;i<n;i++)
	{
		if(a[i+1]<=a[i]&&a[i]>=a[i-1])
		{
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

lucky

遍历l到r

把每一个数分解,各数位相加,取最大值

输出最大值

结束

#include <bits/stdc++.h>
using namespace std;
long long jj(long long n)
{
	long long a=0;
	while(n){
		a+=n%10;
		n=n/10;
	}
	return a;
}
int main() {
	long long l,r,mx=INT_MIN;
	cin>>l>>r;
	for(long long i=l;i<=r;i++)
	{
		mx=max(jj(i),mx);
	}
	cout<<mx;
	return 0;
}

abc

输入

遍历

将a,b,c统计

b,c统计时分别-a的数量与-b的数量

ACCODE

#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	int a=0,b=0,c=0;
	cin>>s;
	int len =s.length();
	for(int i=0;i<len;i++)
	{
		if(s[i]=='a')
		{
			a++;
		}
		if(a>0&&s[i]=='b')
		{
			b++;
			a--;
		}
		if(b>0&&s[i]=='c')
		{
			c++;
			b--;
		}
	}
	cout<<c;
	return 0;
}

总结

  1. long long!! long!!! long long!!!
  2. 判断其他情况!!
posted @ 2024-10-13 14:58  amcplayer  阅读(18)  评论(0)    收藏  举报