栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【AtCoder】【Beginner Contest 221】A-D

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【AtCoder】【Beginner Contest 221】A-D

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

#include
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
#include
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
#include
#include
#include
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
#include
#include
using namespace std;
const int N = 2e5 + 5;
int n;

int main()
{
	cin >> n;
	vector >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());//排序排出先后顺序

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/296452.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号