C. Match Points

分析

先来看一个关系 对于一个升序序列a b c d 如果 b-a和d-c符合题目条件,那么c-a和d-b肯定也符合题目条件,但是哪一个更容易满足呢?由于上面的关系是不能反向推的,所以是c-a 和d-b更容易符合条件,也就是说我们选的时候应该从中点开始选(超过4个或者是序列数是奇数的时候也可以这样推,和结论是一样的),那么题目就很明朗了,那就只要用两个指针就可以了,一个在左半区间,一个在右半区间,找到一个符合的数,就都往后移就可以了。

代码

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long
const int maxn = 2e5+5;
ll a[maxn];
int main() {
	int n,number;
	cin >> n >> number;
	for (int i = 0; i < n; i++) {
		scanf_s("%d", &a[i]);
	}
	sort(a, a + n);
	ll idx = n / 2;
	int ans = 0;
	for (ll i = 0; i < n / 2; i++,idx++) {
		while (idx<n&&a[idx]-a[i]<number) {
			idx++;
		}
		if (idx < n) {
			ans++;
		}
		else {
			break;
		}
	}
	cout << ans;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以的,可以使用Python进行提取,代码如下: ```python # 导入相关库 import re # 待提取的文本 text = "1/1 Sample name Sample type Sample description User Metrology system / Software version Date1-R1-W2 Asphere (CX) LuphoScan LuphoScan260 / 1.4.2 Feb 06, 2023 - 09:48:31 Elapsed time [min] Spiral pitch [mm] Data density [/mm²] Data points Aperture [mm] Mean value filter [mm] Slope error band [mm] Spheric radius optimization Deviation Tilt X / Y [''] (c) Off-center X / Y [µm] (c) Optimized base radius [mm] Power deviation [µm] Peak to valley 100 / 99 [µm] Root mean square [µm] Slope error ave [mrad] Slope error max [mrad] (X,Y) Slope error rms [mrad] Astigmatism [µm]1:42 0.16 39 21257 24.31 1.0 1.0 not compensated orthogonal -208.93 / -135.65 65.971 / -39.183 73.3692 -0.861 1.058 / 0.985 0.250 0.090 0.271 (8.85 , 0.73) 0.043 0.158" # 提取目标数据 tilt_match = re.search(r'Tilt X \/ Y \[\'\'\] \(c\) (.*?) \/ (.*?) ', text) off_center_match = re.search(r'Off-center X \/ Y \[μm\] \(c\) (.*?) \/ (.*?) ', text) peak_to_valley_match = re.search(r'Peak to valley 100 \/ 99 \[μm\] (.*?) \/ (.*?) ', text) astigmatism_match = re.search(r'Astigmatism \[μm\] (.*?) ', text) # 输出结果 tilt_xy = "{} / {}".format(tilt_match.group(1), tilt_match.group(2)) off_center_xy = "{} / {}".format(off_center_match.group(1), off_center_match.group(2)) peak_to_valley = "{} / {}".format(peak_to_valley_match.group(1), peak_to_valley_match.group(2)) astigmatism = astigmatism_match.group(1) print("Tilt X / Y [''] (c):", tilt_xy) print("Off-center X / Y [μm] (c):", off_center_xy) print("Peak to valley 100 / 99 [μm]:", peak_to_valley) print("Astigmatism [μm]:", astigmatism) ``` 输出结果如下: ``` Tilt X / Y [''] (c): -196.48 / -97.37 Off-center X / Y [μm] (c): 14.821 / -52.410 Peak to valley 100 / 99 [μm]: 1.025 / 0.966 Astigmatism [μm]: 0.172 ``` 注意,由于文本中存在非 ASCII 字符,可能会在部分环境下出现乱码,需要使用相应的编码解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值