0
点赞
收藏
分享

微信扫一扫

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

 AcWing 3826. 青蛙跳 

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

输入样例:

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. 最小正整数

2021-09-04 AcWing第15场周赛 一,二题_最小公倍数_02

 

输入样例:

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;
}
}


举报

相关推荐

[Acwing] 第 49 场周赛

Acwing 第 42 场周赛

acwing 第24场周赛

acwing第42场周赛

Acwing第 44 场周赛【完结】

AcWing第46场周赛总结

0 条评论