[bzoj1455]罗马游戏
2016-06-01 20:24
411 查看
题目大意
需要兹瓷集合合并与删去集合内最小值。可并堆
还能说什么呢,裸的……#include<cstdio> #include<algorithm> #define fo(i,a,b) for(i=a;i<=b;i++) using namespace std; const int maxn=1000000+10; int fa[maxn],dis[maxn],left[maxn],right[maxn],a[maxn],root[maxn]; bool bz[maxn]; int i,j,k,l,t,n,m; char ch; char get(){ char ch=getchar(); while (ch!='M'&&ch!='K') ch=getchar(); return ch; } int read(){ int x=0; char ch=getchar(); while (ch<'0'||ch>'9') ch=getchar(); while (ch>='0'&&ch<='9'){ x=x*10+ch-'0'; ch=getchar(); } return x; } int getfa(int x){ return fa[x]?fa[x]=getfa(fa[x]):x; } int merge(int x,int y){ if (!x||!y) return x+y; if (a[x]>a[y]) swap(x,y); right[x]=merge(right[x],y); if (dis[left[x]]<dis[right[x]]) swap(left[x],right[x]); dis[x]=dis[right[x]]+1; return x; } int deletemin(int x){ return merge(left[x],right[x]); } int main(){ n=read(); fo(i,1,n) a[i]=read(),root[i]=i; m=read(); fo(i,1,m){ ch=get(); if (ch=='M'){ j=read();k=read(); if (bz[j]||bz[k]) continue; j=getfa(j); k=getfa(k); if (j==k) continue; fa[j]=k; root[k]=merge(root[j],root[k]); } else{ j=read(); if (bz[j]) printf("0\n"); else{ j=getfa(j); printf("%d\n",a[root[j]]); bz[root[j]]=1; root[j]=deletemin(root[j]); } } } }
相关文章推荐
- ASP常用代码段
- 第十三周项目—阅读、修改和运行关于交通工具类的程序(3)
- 关于存储器重映射
- 旋转ImageView
- git pull时遇到git pull error :error: remote ref is at but expected问题的解决办法
- ios中object c纯代码开发屏幕适配处理方法
- 安卓菜鸟的理解之路之:match_parent、fill_parent与wrap_content的区别与作用
- 深度学习指南:基于Ubuntu从头开始搭建环境
- Fresco
- Java基础知识:java.util包-Date、Calendar、Random类等
- Hadoop(十一):Hadoop生态圈上Pig,Hive,HBase的关系
- 【摘】解决数学问题一般性解决思路
- 【matlab函数】——str2func函数的使用
- C#之三十八 简单工厂设计模式
- 最近积累的一些问题
- HANA对于硬件的认证
- 6-15 A/D转换
- cmd下如何批处理更改文件后缀
- (服务)service
- C#之三十八 简单工厂设计模式