IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> Codeforces Round #786 (Div. 3)(A—E题解) -> 正文阅读

[C++知识库]Codeforces Round #786 (Div. 3)(A—E题解)

A. Number Transformation

题意:给你一个x一个y,求出x乘a次b得到y。输出a和b,无解的话输出0 0

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>

#define endl '\n'

using namespace std;

const int N = 1e5 + 10;

void solve()
{
	int x, y;
	cin >> x >> y;
	if (y % x == 0)
	{
		cout << 1 << ' ' << y / x << endl;
	}
	else
	{
		cout << 0 << ' ' << 0 << endl;
	}
}

int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}

B. Dictionary

题意:有650个字符串,输出当前给的字符串是第几个。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <unordered_map>

#define endl '\n'

using namespace std;

const int N = 1e5 + 10;

unordered_map<string, int> st;

void solve()
{
	string s;
	cin >> s;
	int res = 25 * (s[0] - 'a');
	if (s[1] < s[0])
	{
		res += s[1] - 'a';
	}
	else
	{
		res += s[1] - 'a' - 1;
	}
	cout << res + 1 << endl;
}

int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}

C. Infinite Replacement

题意:给出一个只包含a的字符串,然后给出另外一个字符串b,可以用b字符串换掉源串中的’a’,求能出现多少种字符串。

思路:求出原串的长度n,如果b串长度为1,那么判断b是不是a,

如果是,那么结果为1,否则结果为2n,如果b串长度不为1,判断b串中是否有‘a’,如果有那个结果-1,否则结果也是 2n

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>

#define endl '\n'

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;

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

void solve()
{
	string a;
	string b;
	cin >> a >> b;
	bool flag = false;
	for (int i = 0; i < b.size(); i++)
	{
		if (b[i] == 'a')
		{
			flag = true;
		}
	}
	if (b.size() >= 2 && flag)
	{
		cout << -1 << endl;
	}
	else
	{
		if (b == "a")
		{
			cout << 1 << endl;
			return;
		}
		int num = a.size();
		cout << ksm(2, num) << endl;
	}
}

int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}

D. A-B-C Sort

题意:给一个原始数组,然后这个数组每次将最后一个数移动到b数组中间,如果b数组是奇数长度,那么可以放到中间数的左或右边。a数组为空时,将b数组中间的那个数放到c后面。求这样下来c能否是有序的。

思路:整体看下来就是只有连续两个数之间是可以有交换的关系,而且是倒数第一个和倒数第二个数,倒数第三个数和倒数第四个数。那么可以倒着每两个数之间排序,最后判断是否有序即可。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>

#define endl '\n'

using namespace std;

const int N = 2e5 + 10;

int a[N];

void solve()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = n - 2; i >= 0; i -= 2)
    {
        if (a[i + 1] < a[i])
        {
            swap(a[i + 1], a[i]);
        }
    }
    if (is_sorted(a, a + n))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

E. Breaking the Wall

题意:可以打一个位置的墙,打的位置掉两点血,旁边的两片墙掉一点,问把任意两面墙打掉需要最少多少下
思路:暴力找下三种情况,隔一扇墙,连续两扇,互不相关的两扇。然后求最小的值。

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;

int check1(int a, int b) // a b
{
	if (a < b)
	{
		swap(a, b);
	}
	if(b * 2 < a)
	{
		return (a + 1) / 2;
	}
	int res = a - b;
	a -= (a - b) * 2;
	res += a / 3 * 2;
	if (a % 3 == 1)
	{
		res += 1;
	}
	else if (a % 3 == 2)
	{
		res += 2;
	}
	return res;
}

int check2(int a, int b) // a x b
{
	if (a < b) swap(a, b);
	int res = b;
	res += (a - b + 1) / 2;
	return res;
}

int a[N];

int main()
{
	int res = INF;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for (int i = 1; i < n; i++)
	{
		res = min(res, check1(a[i], a[i + 1]));
	}
	for (int i = 2; i < n; i++)
	{
		res = min(res, check2(a[i - 1], a[i + 1]));
	}
	sort(a + 1, a + n + 1);
	res = min(res, (a[1] + 1) / 2 + (a[2] + 1) / 2);
	cout << res << endl;
	return 0;
}

这个判断写麻烦了,直接加2除以三就行了
因为两个连续的可以每次攻击不亏损伤害(3点),最后一次亏损的加2再算就行
太菜了

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2022-05-05 10:59:30  更:2022-05-05 11:02:22 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/21 1:34:42-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码