HDU 2860 (模拟+并查集)
Regroup
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1057 Accepted Submission(s):
297
build software to help them regroup the battalions or companies.
As the
tradition of army, soldiers are rated according his or her abilities, taking the
rate as an integer. The fighting capacity of a company is determined by the
soldier in this company whose rate is lowest. Now the recruits those rated are
coming and join to their companies according to the order form HQ.
With the
coming of new recruits, a big regroup action reached, asking to merge some
companies into one. The designation of a company, however, will not be canceled,
but remain for memorialize what the company is done, means the designation of
the company is still exist, but the company is gone, so it is unable to ask
recruits to join this company, or merge the company into others.
A strange
thing is, the orders sometimes get wrong, send newbie to a company which is
already merged into another, or mentioned some only-designation-existed
companies. Such order could be rejected.
The brigadier wants to know every
change of each order, so the program should able to report the status of every
order, telling whether it is accept, and can query the fighting capacity of
specified company. (To simplify, companies are numbered from 0 to n-1
For each case, the
integers in first line, n, k, m, telling that there are n companies, k soldiers
already, and m orders needs be executed. (1<=n ,k ,m<=100000).
Then k
lines with two integers R and C for each, telling a soldier with rate R is now
in company C
Then m lines followed, containing 3 kinds of orders, in upper
case:
AP x y
A recruit with ability rate x were asked to join company y.
(0<=x<2^31, 0<=y<n)
MG x y
Company x and company y is
merged. The new company is numbered as x. (0<=x, y<n)
GT
x
Report the fighting capacity of company x. (0<=x<n)
result.
For AP and MG order, print “Accept” if it is able to be done, and
execute it, or “Reject” if it is an illegal order.
For GT order, if company x
is still exist (not merged into others), print as “Lowest rate: y.” which y is
the minimal rate of soldiers in this company. If there is no one in this
company, tell "Company x is empty." If company x is already merged into others,
print "Company x is a part of company z." z is the company where the company x
is in.
Print a blank line after each case
5 0
5 1
5 2
5 1
5 0
GT 0
GT 3
AP 3 3
GT 3
GT 4
MG 3 4
GT 4
MG 1 3
GT 4
GT 1
Company 3 is empty.
Accept
Lowest rate: 3.
Company 4 is empty.
Accept
Company 4 is a part of company 3.
Accept
Company 4 is a part of company 1.
Lowest rate: 3.
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
int f[100005];
int d[100005];
int fig[100005];
int vis[100005];
int getf(int v){return f[v]==v?v:f[v]=getf(f[v]);}
int main()
{
int n,m,i,j,k,x,y,q,r,c;
char s[30];
while(cin>>n>>k>>q){
memset(d,0,sizeof(d));
memset(fig,inf,sizeof(fig));
for(i=0;i<n;++i) f[i]=i,vis[i]=1;
for(i=1;i<=k;++i){
scanf("%d%d",&r,&c);
fig[c]=min(fig[c],r);
d[c]++;
}
while(q--){
scanf(" %s",s);
if(!strcmp(s,"AP")){ scanf("%d%d",&x,&y);
if(!vis[y]) puts("Reject");
else {
puts("Accept");
d[y]++;
fig[y]=min(fig[y],x);
}
}
else if(!strcmp(s,"MG")){ scanf("%d%d",&x,&y);
if(!vis[x]||!vis[y]||(x==y)) {puts("Reject");continue;}
puts("Accept");
d[x]+=d[y];
d[y]=0;
vis[y]=0;
fig[x]=min(fig[x],fig[y]);
fig[y]=inf;
f[y]=x;
}
else if(!strcmp(s,"GT")){ scanf("%d",&y);
if(vis[y]&&d[y]>0) printf("Lowest rate: %d.\n",fig[y]);
else if(vis[y]&&d[y]==0) printf("Company %d is empty.\n",y);
else if(!vis[y]) printf("Company %d is a part of company %d.\n",y,getf(y));
}
} puts("");
}
return 0;
}
HDU 2860 (模拟+并查集)的更多相关文章
- 2019牛客暑期多校训练营(第八场)E:Explorer(LCT裸题 也可用线段树模拟并查集维护连通性)
题意:给定N,M,然后给出M组信息(u,v,l,r),表示u到v有[l,r]范围的通行证有效.问有多少种通行证可以使得1和N连通. 思路:和bzoj魔法森林有点像,LCT维护最小生成树. 开始和队友 ...
- HDU 2818 (矢量并查集)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2818 题目大意:每次指定一块砖头,移动砖头所在堆到另一堆.查询指定砖头下面有几块砖头. 解题思路: ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列
A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- hdu 1116 欧拉回路+并查集
http://acm.hdu.edu.cn/showproblem.php?pid=1116 给你一些英文单词,判断所有单词能不能连成一串,类似成语接龙的意思.但是如果有多个重复的单词时,也必须满足这 ...
- Bipartite Graph hdu 5313 bitset 并查集 二分图
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5313 题意: 给出n个顶点,m条边,问最多添加多少条边使之构成一个完全二分图 存储结构: bitset ...
- hdu 3081(二分+并查集+最大流||二分图匹配)
Marriage Match II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU - 5441 (离线+并查集)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5441 题意:给你n,m,k,代表n个城市,m条边,k次查询,每次查询输入一个x,然后让你一个城市对(u,v ...
- hdu 3536【并查集】
hdu 3536 题意: 有N个珠子,第i个珠子初始放在第i个城市.有两种操作: T A B:把A珠子所在城市的所有珠子放到B城市. Q A:输出A珠子所在城市编号,该城市有多少个珠子,该珠子转移了 ...
- HDU 1829 分组并查集
题意:有两种性别,每组数据表示是男女朋友,判断输入的几组数据是否有同性恋 思路:http://blog.csdn.net/iaccepted/article/details/24304087 分组并查 ...
随机推荐
- Cisco设备开启telnet登录
思科设备怎么开启telnet登录 configuration line vty 0 4SW1(config-line)#transp input telne
- python基础之练习题(二)
九九乘法表 i = 0 #while 九九乘法表 j = 0 while i < 9: i += 1 while j<9: j += 1 sum = i + j total="% ...
- Python开发【模块】:Pygal 绘制直方图
Pygal Pygal可用来生成可缩放的矢量图形文件,对于需要在尺寸不同的屏幕上显示的图表,这很有用,可以自动缩放,自适应观看者的屏幕 1.Pygal模块安装 ① Windows系统 # Pygal模 ...
- Get,Post请求方式详解
前几天工作中,所有表单我都采用post方法,头儿说那样不好,大型网站上一般都采用get方法,不理解. 在网上摘到一段比较有用的话 减低服务器流量压力根据 HTTP 规范,GET 用于信息获取,而且应该 ...
- Mirror--生成用于镜像用户同步的脚本
USE master GO IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL DROP PROCEDURE sp_hexadecimal GO CREATE PR ...
- Linux相关知识总结
查看CPU使用情况 查看内存 ps命令显示所有运行中的进程等命令 top 命令用来显示CPU的使用情况free命令用来显示内存的使用情况 select和epoll区别select,poll,epoll ...
- 小型网站MYSQL问题二:Percona Xtrabackup实现数据库备份和恢复
1.安装软件仓库(不要问我为什么不用源码安装,好吧,其实我懒.) 1 2 3 4 5 6 7 8 wget https://www.percona.com/downloads/percona-rele ...
- python开发之路目录
Python 目录 基础 python入门 python数据类型.字符编码.文件处理 python函数基础 python函数进阶 python装饰器函数 python装饰器函数 python递归函数 ...
- (16)Cocos2d-x 多分辨率适配完全解析
Overview 从Cocos2d-x 2.0.4开始,Cocos2d-x提出了自己的多分辨率支持方案,废弃了之前的retina相关设置接口,提出了design resolution概念. 3.0中有 ...
- AtCoder Grand Contest 030 Solution
A - Poisonous Cookies 签到. #include <bits/stdc++.h> using namespace std; #define ll long long l ...