【机试练习】【C++】【PAT A1053】Path of Equal Weight(玄学一样的“段错误”)

2023-11-02

此题有较大的玄学,如果将cmp函数的默认返回值更改为true,则会出现最后一个测试用例的“段错误”。
在代码中以“我的天!!!玄学”标识出

#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

struct Node{
   
	int weight;
	vector<int> child;
};
Node t[1010];
vector<vector<int> > serialStore;
vector<int> tmpSerial;
bool cmp(vector<int> a, vector<int> b){
   
	if(a.empty() || b.empty()){
   
		return a.empty();
	}
	int minL = min(a.size(), b.size());
	for(int i = 0; i < minL; i++){
   
		if(a[i] != b[i]) return a[i] > b[i]; // 关键在这里的大于号 
	}
	return false; // 我的天!!玄学 
} 

// 测试cmp是否工作的函数
void sortSerial(){
   
	vector<int> tmp;
	tmp.push_back(10);tmp.push_ba
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【机试练习】【C++】【PAT A1053】Path of Equal Weight(玄学一样的“段错误”) 的相关文章

随机推荐