P9232 [蓝桥杯 2023 省 A] 更小的数与P9231 [蓝桥杯 2023 省 A] 平方差

P9232 [蓝桥杯 2023 省 A] 更小的数

题目链接:https://www.luogu.com.cn/problem/P9232#submit

题目思路:有2种情况可以达成题意,首先是反转的字符串中第一位大于最后一位,其次是虽然前x位和后x位相同,但是中间不同的位是前面大于后面的,比如22203222也是一种,然后模拟就可以了

题目代码:

#include<bits/stdc++.h>

using namespace std;

using ll = long long;
const ll maxn = 1e18;
const int MOD = 998244353;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

void solve() {
	string s; cin >> s;
	int n = s.size();
	ll cnt = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			if (s[i] > s[j]) {
				cnt++;
			}
			else if (s[i] == s[j]) {
				for (int t = i + 1, tt = j - 1; t < tt; t++, tt--) {
					if (s[t] > s[tt]) {
						cnt++;
						break;
					}
					else if (s[t] < s[tt]) {
						break;
					}
				}
			}
		}
	}
	cout << cnt << '\n';
}

signed main() {

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t1 = 1;
	//cin >> t1;
	while (t1--)
		solve();

	return 0;
}

P9231 [蓝桥杯 2023 省 A] 平方差

题目链接:https://www.luogu.com.cn/problem/P9231
假设y+z=n,y-z=m,则y=(n+m)/2,z=(n-m)/2, 又x=n*m且都为整数,则n和m奇偶性相同,所以x要么为奇数要么为4的倍数
然后遍历就可以了

代码:

#include<bits/stdc++.h>

using namespace std;

using ll = long long;
const ll maxn = 1e18;
const int MOD = 998244353;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

void solve() {
	int l, r; cin >> l >> r;
	int cnt = 0;
	for (int i = l; i <= r; i++) {
		if (i & 1 || i % 4 == 0)
			cnt++;
	}
	cout << cnt << '\n';
}

signed main() {

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t1 = 1;
	//cin >> t1;
	while (t1--)
		solve();

	return 0;
}


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值