【AtCoder】【Beginner Contest 221】A-D

题意:输出32^(a-b)即可。这里敲了个快速幂。

#include<iostream>
using namespace std;
typedef long long ll;

ll q_pow(int a, int b)
{
	ll ans = 1;
	while (b)
	{
		if (b & 1) ans *= a;
		a *= a;
		b >>= 1;
	}
	return ans;
}

int main()
{
	
	ll a, b;
	cin >> a >> b;
	cout << q_pow(32, a - b);
	return 0;
}

 题意:能否通过交换相邻的两位使S串等于T串。

思路:数据范围较小,暴力就完了,复杂度o(n^2)。

#include<iostream>
#include<string>
using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	if (s == t) {  //必不可少的特判
		cout << "Yes";
		return 0;
	}
	for (int i = 0; i <= s.length() - 1; i++)
	{
		swap(s[i], s[i + 1]);  //交换相邻两位
		if (s == t) {
			cout << "Yes";
			return 0;
		}
		swap(s[i], s[i + 1]);  //还原相邻两位
	}
	cout << "No";
	return 0;
}

 

题意:给定一个整数,你可以分离数位构成两个数。问:两个数乘积最大能有多大?

思路:两个数大且接近时乘积最大。

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	sort(s.begin(), s.end(), [](const char& ch1, const char ch2) {
		return ch1 > ch2;
		});  //倒叙排列
	int a = 0, b = 0;
	for (int i = 0; i < s.length(); i++)
	{
		int t = s[i] - '0';

		//动态调整两数(大且接近)
		if (a > b) {
			b = b * 10 + t;
		}
		else
			a = a * 10 + t;
	}
	cout << a * b;
	return 0;
}

 

 

题意:给定一个一个人的上线时间,以及上线天数。问:同时有1-n个人在线的天数位?

思路:类似差分。

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 2e5 + 5;
int n;

int main()
{
	cin >> n;
	vector<pair<int, int> >a;
	for (int i = 0; i < n; i++) 
	{
		int x, y;
		cin >> x >> y;
		a.emplace_back(x, 1);
		a.emplace_back(x + y, -1);
	}
	sort(a.begin(), a.end());//排序排出先后顺序

	vector<int>ans(N, 0);
	int cnt = 0;

    //计算时间段内的人数
	for (int i = 0; i < a.size() - 1; i++)
	{
		cnt += a[i].second;
		ans[cnt] += (a[i + 1].first - a[i].first);
	}
	for (int i = 1; i <= n; i++)
	{
		cout << ans[i] << ' ';
	}
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Sophon、

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

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

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

打赏作者

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

抵扣说明:

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

余额充值