CF317D. Vessels(并查集)
来源:互联网 发布:天猫跟淘宝哪个质量好 编辑:程序博客网 时间:2024/06/15 04:17
#include<cstdio>#include<iostream>#include<string.h>using namespace std;const int maxn=1500000;int n;int sum[maxn];int a[maxn];int f[maxn];int find(int x)//找到下个未装满 {return x==f[x]?x:f[x]=find(f[x]); }void Merge(int x,int y)//合并装满的 {int xx=find(x);int yy=find(y);if(xx>yy){f[yy]=xx;}elsef[xx]=yy;}int main(){while(scanf("%d",&n)!=EOF){memset(a,0,sizeof(a));//容积 memset(sum,0,sizeof(sum));//有多少水 for(int i=1;i<=n;i++){scanf("%d",&a[i]);f[i]=i;//初始化每个集合 }f[n+1]=n+1;int q;scanf("%d",&q);//询问 while(q--){int o;scanf("%d",&o);if(o==1){int index,ha;scanf("%d%d",&index,&ha);while(ha>0){int ff=find(index);if(ff==n+1) break;if(a[ff]-sum[ff]>=ha){sum[ff]+=ha;ha=0;}else{ha-=a[ff]-sum[ff];sum[ff]=a[ff];Merge(ff,ff+1);}index=ff;}} if(o==2){int t;scanf("%d",&t);printf("%d\n",sum[t]);}}}}
阅读全文
0 0
- CF317D. Vessels(并查集)
- codeforces Vessels(并查集)
- CF 371D Vessels 【并查集】
- Codeforces 371D. Vessels【并查集】
- Codeforces Round #218 (Div. 2) D. Vessels(思维 并查集)
- Codeforces Round #218 (Div. 2)---D. Vessels(并查集)
- Codeforces 371D Vessels【思维+并查集】经典套路题
- CF Round #218 (Div. 2) && CF 371D Vessels【并查集】
- Vessels
- Vessels
- Vessels
- 并查集(集并查)
- 并查集(含关系并查集)
- 【并查集】食物链(关系并查集)
- 【并查集】并查集详解(转)
- 分组并查集(种类并查集)
- 并查集, 畅通工程(简单并查集)
- [数据结构]并查集水体POJ2236(并查集)
- 关联规则R语言实战(Apriori算法)
- ural1183&&poj1141 Brackets Sequence(区间DP+记录路径)
- Linux笔记汇总
- js实现ctrl+v粘贴上传图片(兼容chrome、firefox、ie11)
- 欢迎使用CSDN-markdown编辑器
- CF317D. Vessels(并查集)
- AES加密——C语言实现 与 原理分析
- 器---查看api
- urelsession 文件下载
- Qt Creator:DirMainWindow(对文件的操作)
- C++内存分配秘籍—new,malloc,GlobalAlloc,野指针详解
- linux中软件的安装
- 为什么使用css
- BZOJ 2434 阿狸的打字机 (AC自动机 fail树 树状数组)