求助玄学问题
  • 板块学术版
  • 楼主Bamboo_Day
  • 当前回复8
  • 已保存回复8
  • 发布时间2023/3/3 19:53
  • 上次更新2023/10/23 23:14:49
查看原帖
求助玄学问题
482452
Bamboo_Day楼主2023/3/3 19:53

题目传送门

大佬们先看一段丑陋的代码

#include <bits/stdc++.h>
using namespace std;
bool cmp(long long x,long long b){
	if(x != b) return x>b;
}
long long n,b,a[30000];
unsigned long long sum=0;
int main(){
	cin>>n>>b;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		sum=sum+a[i];
		
		if(sum>=b){
			cout<<i;
			break;
		}
	}
	return 0;
}

这里注意第3行的cmp函数,将if去掉就可以过

蒟蒻分析认为这是cmp出了问题

然后我将这个cmp复制下来,写了另外一个排序

#include <bits/stdc++.h>
const int N = 1e6+10;
const int M = (1 << 20) + 3;
const int INF = 0x3f3f3f3f;

using namespace std;
bool cmp(long long x,long long b){
	if(x != b) return x < b;
} 
long long a[N],b;
int main(){
	freopen("sort.in","r",stdin);
	freopen("sort.out","w",stdout);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a+1,a+n+1,cmp);
	for(int i = 1; i <= n; i++){
		cout << a[i] <<" ";
	}
	return 0;
}

然后这是我自己给出的标程

#include <bits/stdc++.h>
const int N = 1e6+10;
const int M = (1 << 20) + 3;
const int INF = 0x3f3f3f3f;

using namespace std;
long long a[N];
int main(){
	freopen("sort.in","r",stdin);
	freopen("sort.ans","w",stdout);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a+1,a+n+1);
	for(int i = n; i > 0; i--){
		cout << a[i] <<" ";
	}
	return 0;
}

下面是我的对拍程序

:loop
give.exe
text.exe
answer.exe
fc sort.out sort.ans
if not errorlevel 1 goto loop

生成样例程序

#include <bits/stdc++.h>
const long long N = 1e15+10;
const int M = 1e4+10;
const int INF = 0x3f3f3f3f;

using namespace std;

int main(){
	srand(time(0));
	freopen("sort.in","w",stdout);
	int n = rand() % 1000005;
	cout << n << endl;
	for(int i = 1; i <= n; i++){
		long long a = rand() % N;
		cout<< a << " ";
	}
	return 0;
}

那么从理论上来说,如果cmp是错误的,在对拍的时候应该会报错,但事实上却没有

想过会不会是give是随机化的样例不够完全

于是蒟蒻下载了样例

但是跑出来还是正确的

问了机房的两个大佬他们也不知道为什么

希望大佬能帮忙解决一下这个问题

2023/3/3 19:53
加载中...