2021-10-04【AtCoder Beginner Contest 221】【A-D题解】

A. Seismic magnitude scales

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    long long a,b;
    cin >> a >> b;
    cout << (long long)pow(2, (a - b) * 5);//强制转换不能少
    return 0;
}

B typo

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    string a,b;
    cin >> a;
    cin >> b;
    int cnt = 0;
    if(a==b){
         cout << "Yes";
         return 0;
    }
       
    for (int i = 0; i < a.size()-1;i++){
        swap(a[i], a[i + 1]);
        if(a==b){
            cout << "Yes";
            return 0;
        }
        swap(a[i], a[i + 1]);
    }
    cout << "No";
    return 0;
}

C Select Mul

在这里插入图片描述

#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
string ss;
long long  a[100], x = 0, y = 0, ma = 0;
int cmp(int a, int b) {
	return a > b;
}
int main() {
	cin >> ss;
	int n = ss.size();
	for (int i = 0; i < n; i++) {
		a[i] = ss[i] - '0';
	}
	sort(a, a + n, cmp);
	for (int i = 0; i < n; i++) {
		if (x > y)
            y = y * 10 + a[i];
        else
            x = x * 10 + a[i];
    }
// 1 2 3
// 3 2 1  31 2
//321 3
//5 43
//53 4
	cout << x * y;

	return 0;
}

D Online games

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int maxn = 2e5 + 10;
PII p[maxn << 1];
int n, ans[maxn];
 
int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        p[i * 2 - 1] = make_pair(a, 1);
        p[i * 2] = make_pair(a + b, -1);
    }
    sort(p + 1, p + 2 * n + 1);
    int cover = p[1].second;
    for(int i = 2; i <= 2 * n; ++i)
    {
        ans[cover] += p[i].first - p[i - 1].first;
        cover += p[i].second;
    }
    for(int i = 1; i <= n; ++i)
        printf("%d ", ans[i]);
    putchar('\n');
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Eternity_GQM

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

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

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

打赏作者

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

抵扣说明:

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

余额充值