洛谷P1456 Monkey King

本文介绍了一个模拟猴子冲突的算法问题,通过构建数据结构来解决猴子之间的冲突,并跟踪它们的力量变化及新形成的友谊关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

Once in a forest, there lived N aggressive monkeys. At the beginning, they each does things in its own way and none of them knows each other. But monkeys can't avoid quarrelling, and it only happens between two monkeys who does not know each other. And when it happens, both the two monkeys will invite the strongest friend of them, and duel. Of course, after the duel, the two monkeys and all of there friends knows each other, and the quarrel above will no longer happens between these monkeys even if they have ever conflicted.

Assume that every money has a strongness value, which will be reduced to only half of the original after a duel(that is, 10 will be reduced to 5 and 5 will be reduced to 2).

And we also assume that every monkey knows himself. That is, when he is the strongest one in all of his friends, he himself will go to duel.

一开始有n只孤独的猴子,然后他们要打m次架,每次打架呢,都会拉上自己朋友最牛叉的出来跟别人打,打完之后战斗力就会减半,每次打完架就会成为朋友(正所谓不打不相识o(∩_∩)o )。问每次打完架之后那俩猴子最牛叉的朋友战斗力还有多少,若朋友打架就输出-1.

输入输出格式

输入格式:

There are several test cases, and each case consists of two parts.

First part: The first line contains an integer N(N<=100,000), which indicates the number of monkeys. And then N lines follows. There is one number on each line, indicating the strongness value of ith monkey(<=32768).

Second part: The first line contains an integer M(M<=100,000), which indicates there are M conflicts happened. And then M lines follows, each line of which contains two integers x and y, indicating that there is a conflict between the Xth monkey and Yth.

有多组数据

输出格式:

For each of the conflict, output -1 if the two monkeys know each other, otherwise output the strength value of the strongest monkey among all of its friends after the duel.

输入输出样例

输入样例#1: 
5
20
16
10
10
4
5
2 3
3 4
3 5
4 5
1 5
输出样例#1: 
8
5
5
-1
10

说明

题目可能有多组数据

左偏树经典,结果调了一晚上,吃枣药丸。。。

附上苦心调好的代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define MAXN 100010
using namespace std;
int n,m;
struct node{
	int son[2];
	int v,dis,f;
}a[MAXN];
inline int read(){
	int date=0,w=1;char c=0;
	while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
	while(c>='0'&&c<='9'){date=date*10+c-'0';c=getchar();}
	return date*w;
}
int merge(int x,int y){
	if(!x||!y)return x+y;
	if(a[x].v<a[y].v)swap(x,y);
	a[x].son[1]=merge(a[x].son[1],y);
	a[a[x].son[1]].f=x;
	if(a[a[x].son[0]].dis<a[a[x].son[1]].dis)swap(a[x].son[0],a[x].son[1]);
	if(a[x].son[1])a[x].dis=a[a[x].son[1]].dis+1;
	else a[x].dis=0;
	return x;
}
int find(int x){
	while(a[x].f!=x)x=a[x].f;
	return x;
}
int deletemin(int x){
	int lson=a[x].son[0],rson=a[x].son[1];
	a[x].dis=a[x].son[0]=a[x].son[1]=0;
	a[lson].f=lson;a[rson].f=rson;
	return merge(lson,rson);
}
int main(){
	int x,y,root,left,right;
	while(~scanf("%d\n",&n)){
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++){
			a[i].v=read();
			a[i].f=i;
		}
		m=read();
		while(m--){
			x=read();y=read();
			x=find(x);y=find(y);
			if(x==y){
				printf("-1\n");
				continue;
			}
			a[x].v/=2;a[y].v/=2;
			left=deletemin(x),right=deletemin(y);
			left=merge(left,x);right=merge(right,y);
			root=merge(right,left);
			printf("%d\n",a[root].v);
		}
	}
	return 0;
}
内容概要:该论文聚焦于T2WI核磁共振图像超分辨率问题,提出了一种利用T1WI模态作为辅助信息的跨模态解决方案。其主要贡献包括:提出基于高频信息约束的网络框架,通过主干特征提取分支和高频结构先验建模分支结合Transformer模块和注意力机制有效重建高频细节;设计渐进式特征匹配融合框架,采用多阶段相似特征匹配算法提高匹配鲁棒性;引入模型量化技术降低推理资源需求。实验结果表明,该方法不仅提高了超分辨率性能,还保持了图像质量。 适合人群:从事医学图像处理、计算机视觉领域的研究人员和工程师,尤其是对核磁共振图像超分辨率感兴趣的学者和技术开发者。 使用场景及目标:①适用于需要提升T2WI核磁共振图像分辨率的应用场景;②目标是通过跨模态信息融合提高图像质量,解决传统单模态方法难以克服的高频细节丢失问题;③为临床诊断提供更高质量的影像资料,帮助医生更准确地识别病灶。 其他说明:论文不仅提供了详细的网络架构设计与实现代码,还深入探讨了跨模态噪声的本质、高频信息约束的实现方式以及渐进式特征匹配的具体过程。此外,作者还对模型进行了量化处理,使得该方法可以在资源受限环境下高效运行。阅读时应重点关注论文中提到的技术创新点及其背后的原理,理解如何通过跨模态信息融合提升图像重建效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值