Good Bye 2018 A. New Year and the Christmas Ornament

时间:2023-03-09 00:51:58
Good Bye 2018 A. New Year and the Christmas Ornament

传送门

https://www.cnblogs.com/violet-acmer/p/10201535.html

题解:

  这题没什么好说的,读懂题意就会了。

比赛代码:

 #include<iostream>
using namespace std; int y,b,r;
int Solve()
{
if(b < || r < )
return ;
for(int i=y;i >= ;--i)
if(b >= i+ && r >= i+)
return *(i+);
return ;
}
int main()
{
cin>>y>>b>>r;
cout<<Solve();
return ;
}

暴力O(n)

赛后整理代码:

 #include<iostream>
#include<cstdio>
using namespace std; int y,b,r; int Solve()
{
if(b >= y+ && r >= y+)
return *(y+);
if(y >= b- && r >= b+)
return *b;
if(b >= r- && y >= r-)
return *(r-);
return ;
}
int main()
{
scanf("%d%d%d",&y,&b,&r);
printf("%d\n",Solve());
return ;
}

O(1)