牛客周赛 Round 54 解题

清楚姐姐的糖葫芦

代码

#include

using namespace std;

string a;
int res;

int main(){
    cin>>a;
    
    for(int i=0;i

清楚姐姐买竹鼠

思路

我们就得分情况讨论了,看下三只一起买便宜还是单只买3只便宜,按照这个思想就很好写了。

#include

#define int long long

using namespace std;

int a,b,x;

signed main(){
    cin>>a>>b>>x;
    
    int res;
    
    if(3*a>=b){
        if(x%3*a>=b){
            res=(x/3+1)*b;
        }else{
            res=(x/3)*b+x%3*a;
        }
    }else{
        res=a*x;
    }

    
    cout<

竹鼠饲养物语

思路

我们可以通过观察规律可以知道:

  • 性质1:只要从 1 1 1 开始如果后面是连续的话,就可以算到答案内。
  • 性质2: 1 1 1 我们可以都要。

按照这些性质我们就可以用 map 来装所有数字出现的次数,如果当前的数值是之前数值+1,我们就把答案加上它的个数和上个个数的最小值(为什么呢?因为到当前级肯定是从上一级的基础上来的,也就是不能超过它的个数)

  • 细节:一旦不满足条件,我们立马退出循环,避免出现这种情况:
5
1 1 2 5 6
#include
#include
#include

#define int long long

using namespace std;

const in

你可能感兴趣的:(牛客,算法,图论)