F - The Best Path

 

题意:当每条河只能走一遍而且能遍历所有湖的情况下,输出每个湖的值的最大异或值,如果不存在这种情况输出impossible。

思路:我强大的队友画图找出了规律。。。tql

对于一个湖,算出他出度入度的总和之后,遍历一遍看他有几个奇数,如果有两个奇数或者没有奇数的话就说明可以在每条边都遍历一遍的情况下走遍所有的湖,其他情况就是不能遍历所有的湖直接输出impossible。当全是偶数边的时候,说明是环,那么肯定会回到起点的位置,那么起点的位置就多异或了一遍,最后还得再异或一遍起点的位置,那么我们本题是在任意起点出发,所以我们要遍历所有湖,然后拿我们算好的异或值再异或一下湖的数取最大值,如果有两个奇数边的话就没有回到起始点的情况,所以直接输出我们算的异或值就行了。

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
ll d[100005],a[100005];
int n,m;
void sove(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		d[i]=0;
	}
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		d[a]++;
		d[b]++;
	}
	int con=0;
	for(int i=1;i<=n;i++){
		if(d[i]&1)con++;
	}
	if(con!=0&&con!=2){
		cout<<"Impossible"<<endl;
		return ;
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		int tmp=(d[i]+1)/2;//因为我们算的是出度+入度,所以我们每次算一个湖异或几遍的时候先/2.
		while(tmp--){
			ans^=a[i];
		}
	}
	if(con==2){//当有2个奇数说明不能回到起始点直接输出异或值
		cout<<ans<<endl;
		return ;
	}
	//如果全是偶数说明会回到起点,那么列举一下我们算出来的数和每个起点的值异或起来的数取最大。
	int res=0;
	for(int i=1;i<=n;i++){
		if(d[i]){
			int num=ans^a[i];
			res=max(res,num);
		}
	}
	cout<<res<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie() ,cout.tie() ;
	int t=1;
	cin>>t;
	while(t--){
		sove();
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码主要是进行图像重建的过程,下面是每一句话的注释: - t=time():记录当前时间,用于计算重建时间。 - By default colmap does not generate a reconstruction if less than 10 images are registered. Lower it to 3.:默认情况下,如果注册的图像少于10张,则colmap不会生成重建。将其降低到3。 - mapper_options = pycolmap.IncrementalMapperOptions():创建 pycolmap.IncrementalMapperOptions() 类的对象 mapper_options。 - mapper_options.min_model_size = 3:设置 mapper_options 的最小模型尺寸为 3。 - os.makedirs(output_path, exist_ok=True):使用 makedirs() 函数在指定路径 output_path 创建文件夹,如果文件夹已经存在则不会报错。 - maps = pycolmap.incremental_mapping(database_path=database_path, image_path=img_dir, output_path=output_path, options=mapper_options):使用 pycolmap.incremental_mapping() 函数进行增量式的图像重建,返回重建结果 maps。 - print(maps):打印 maps,用于调试和查看重建结果。 - #clear_output(wait=False):注释掉的语句,可能是用于清除输出缓存的,但是被注释掉了。 - t=time() - t:计算重建时间。 - timings['Reconstruction'].append(t):将重建时间 t 添加到 timings 字典中的 Reconstruction 键对应的列表中。 - print(f'Reconstruction done in {t:.4f} sec'):输出重建时间,保留小数点后四位。 - imgs_registered = 0:记录已经注册的图像数量。 - best_idx = None:初始化最佳重建的索引为 None。 - print ("Looking for the best reconstruction"):打印提示信息,表示正在寻找最佳重建。 - if isinstance(maps, dict)::如果 maps 是字典类型。 - for idx1, rec in maps.items()::遍历 maps 字典中的每一项,其中 idx1 是键,rec 是值。 - print (idx1, rec.summary()):打印 idx1 和 rec 的摘要信息。 - if len(rec.images) > imgs_registered::如果 rec 中注册的图像数量大于已经注册的图像数量。 - imgs_registered = len(rec.images):将注册的图像数量更新为 rec 中注册的图像数量。 - best_idx = idx1:更新最佳重建的索引为当前的 idx1。 - if best_idx is not None::如果存在最佳重建的索引。 - print (maps[best_idx].summary()):打印最佳重建的摘要信息。 - for k, im in maps[best_idx].images.items()::遍历最佳重建中的每一个图像。 - key1 = f'{dataset}/{scene}/images/{im.name}':构造输出结果的键值,格式为 dataset/scene/images/im.name。 - out_results[dataset][scene][key1] = {}:在输出结果字典中为当前图像的键值创建一个空字典。 - out_results[dataset][scene][key1]["R"] = deepcopy(im.rotmat()):将当前图像的旋转矩阵 R 深度复制到输出结果字典中。 - out_results[dataset][scene][key1]["t"] = deepcopy(np.array(im.tvec)):将当前图像的位移矩阵 t 深度复制到输出结果字典中。 - print(f'Registered: {dataset} / {scene} -> {len(out_results[dataset][scene])} images'):输出已经注册的图像数量。 - print(f'Total: {dataset} / {scene} -> {len(data_dict[dataset][scene])} images'):输出总共需要注册的图像数量。 - create_submission(out_results, data_dict):调用 create_submission() 函数生成提交结果。 - gc.collect():手动调用 Python 的垃圾回收机制,释放内存。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值