跳到正文

个人记录

对拍

xinlong666约 4 分钟
原文

这是 2025年10月26日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年10月23日
收录
2025年12月12日
更新
2026年10月27日
篇幅
约 4 分钟

版本

  1. v2当前
  2. v1

源代码

C++
#include <bits/stdc++.h>//ydm.cpp
#define int long long
#define endl '\n'
using namespace std;
signed main (){
	freopen("a.in","r",stdin);
	freopen("zj.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,x;
	cin >> n >> x;
	int l = 0 , r = n;
	int a[n+2];
	for (int i = 1 ; i <= n ; i ++){
		cin >> a[i];
	}
	a[0] = -1;
	a[n+1] = 1e9;
	int ans = 0;
	while(l<=r){
		int mid = (l+r+1)>>1;
		//cout << mid << ' ';
		if(a[mid]>=x){
			r = mid-1;
			ans = mid;
		}else{
			l = mid+1;
		}
	}
	cout << ans << endl;
	return 0;
} 

暴力代码

C++
#include <bits/stdc++.h>//bl.cpp
#define int long long
#define endl '\n'
using namespace std;
signed main (){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	freopen("a.in","r",stdin);
	freopen("bl.out","w",stdout);
	int n,x;
	cin >> n >> x;
	int l = 0 , r = n;
	int a[n+2];
	for (int i = 1 ; i <= n ; i ++){
		cin >> a[i];
	}
	for (int i = 1 ; i <= n ; i ++){
		if(a[i]>=x){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
} 

对拍

C++
#include <bits/stdc++.h>//sc.cpp
#define int long long
#define endl '\n'
using namespace std;
signed main (){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	freopen("a.in","w",stdout);
	srand(time(0));
	int n = rand()%100+1;
	int m = rand()%n+1;
	cout << n << ' ';
	int a[n+2];
	int dq = 1;
	for (int i = 1 ; i <= n ; i++){
		a[i] = dq;
		dq = rand()%1000000+1;
	}
	sort(a+1,a+n+1);
	cout << a[m] << endl;
	for (int i = 1;  i <= n ; i ++){
		cout << a[i] << ' ';
	} 
	return 0;
} 

放到同一个文件夹编译运行一遍后

新建文本文档后(记得显示后缀)

把他改为 xxx.bat

右键+编辑

打开cmd,输入 xxx.bat

按ctrl+c停止 然后你就可以愉快地对拍了