2021-09-04 AcWing第15场周赛 一,二题

 AcWing 3826. 青蛙跳 


输入样例:

6
5 2 3
100 1 4
1 10 5
1000000000 1 6
1 1 1000000000
1 1 999999999

输出样例:

8
198
-17
2999999997
0
1

一开始的做法,但是碰见大数会爆

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int t,n;
    cin >> t;
    while (t -- )
    {
        int a,b,k;
        scanf("%d%d%d", &a, &b, &k);
        if(k%2) cout << a + k/2*(a-b) << endl;
        else cout << k/2*(a-b) << endl;
    
    }
    return 0;
}

改进后(将奇偶的表达式合并,同时注意到了题目所给的数据范围采用了long long) 

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t -- )
    {
        long long a,b,k;
        scanf("%ld%ld%ld", &a, &b, &k);
        long long res = k/2*(a-b) + (k&1)*a;
        cout << res<< endl;
    
    }
    return 0;
}

AcWing 3827. 最小正整数


 

输入样例:

6
375 4
10000 1
38101 0
123456789 8
1 0
2 0

输出样例:

30000
10000
38101
12345678900000000
1
2

思路:

既然要求n与10^m的最小公倍数,那么最终结果末尾0的个数至少为m,而10^m  =>  2^m * 5^m, 我们只需要判断在末尾必然会输出的m个0,可以为这m个0前面的倍数分配多少个"2"因数,多少"5"因数,且个数不得大于m(多了分担不了)

#include <iostream>
using namespace std;

int main() {
    int t;
    int n,m;
    cin >> t;
    while (t -- )
    {
        scanf("%d%d", &n, &m);
        for (int i = 0; i < m; i ++ )
            if(n%2==0)
                n /= 2;
        for (int i = 0; i < m; i ++ )
            if(n%5==0)
                n /= 5;
        cout << n;
        while (m -- ){
            cout << '0';
        }
        cout << endl;
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

泥烟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值