Codeforces 566 D. Restructuring Company】的更多相关文章

Description 一开始有 \(n\) 个元素,可以进行几个操作. 合并 \(x,y\) . 合并 \(x,x+1,...,y\) . 询问 \(x,y\) 是否在一个集合中. Sol 并查集+链表. 第二个询问,一直用链表找 \(pre\) 优化一下就可以了. 另外 51Nod 1525 重组公司. Code #include<cstdio> #include<utility> #include<algorithm> #include<iostream&g…
题目链接: D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Even the most successful company can go through a crisis period when you have to make a hard decision — to re…
Restructuring Company Even the most successful company can go through a crisis period when you have to make a hard decision — to restructure, discard and merge departments, fire employees and do other unpleasant stuff. Let's consider the following mo…
D. Restructuring Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/566/problem/D Description Even the most successful company can go through a crisis period when you have to make a hard decision — to restructure, disca…
http://codeforces.com/contest/566/problem/D D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Even the most successful company can go through a crisis period when yo…
传送门 D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Even the most successful company can go through a crisis period when you have to make a hard decision — to rest…
题意:给定 3 种操作, 第一种 1 u v 把 u 和 v 合并 第二种 2 l r 把 l - r 这一段区间合并 第三种 3 u v 判断 u 和 v 是不是在同一集合中. 析:很容易知道是用并查集来做,但是如果单纯的用并查集,肯定是要超时的,所以要用链表,如果合并了,就把链表指向, 这样就搞定了这个题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #i…
[题目链接]:http://codeforces.com/problemset/problem/566/D [题意] 给你n个人; 一开始每个人都隶属于一个部门; 之后给你q个操作; 3种操作类型; 1.把x和y所在的部门的所有人都并在一个新的部门 2.把x..y这个区间范围里面的人所在的部门的所有人都并在一个部门; 3.查询x和y是否在同一个部门; [题解] 并查集; 这里把x..y并在一起; 相当于有y-x个合并操作 ①for (int i = x+1;i<=y;i++) merge(i-1…
[题目链接]:http://codeforces.com/contest/794/problem/C [题意] 有n个位置; 两个人; 每个人都有n个字符组成的集合s1,s2(可以有重复元素); 然后两人轮流从各自的集合中取出一个字符; 把它放在这n个位置中的任意一个位置; 其中一个人想要让这n个字符组成的字符串字典序尽量小; 另外一个人则想让他尽量大; 问你最后字符串会变成什么样 [题解] s1和s2是两个人的集合 可以先把s1升序排; 然后s2降序排; 设ls1,ls2分别为s1和s2最左的…
题目链接:http://codeforces.com/contest/794/problem/C 题意:有两个人每个人都有一个长度为n的字符串,两人轮流拿出一个字符串,放在一个长度为n的字符串的指定位置中,第一个 人他想让最后组成的字符串尽可能小,另一个人想要字符串尽可能的大.他们互相知道各自手中有什么字符串,最后输出组成的 字符串 #include <iostream> #include <cstring> #include <string> #include <…