On September 22, 2004, Oceanic Flight 815 crashed on a mysterious island somewhere in the pacific. There actually were survivors in the crash , N survivors . The mysterious island kept on moving in space - time, so no rescue reached them. Initially e…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1604 题意: 平面直角坐标系中,有n个点(n <= 100000,坐标范围10^9). 给定r,当两个点的曼哈顿距离<=r时,认为这两个点在同一个“群”中. 问你共有多少个群,以及点的数量最多的群有多少个点. 题解: 本题的核心在于:如何枚举一个点周围满足“曼哈顿距离<=r”的点. 由于 曼哈顿距离 = |x1 - x2| + |y1 - y2|. x和y相互影响,不能单纯按x或…
Taplu and Abhishar loved playing scrabble. One day they thought of inventing a new game using alphabet tiles. Abhishar wrote a string using tiles and gave a set of pairs (i,j) to Taplu. Pair “i, j” (0 based indexing) means that Taplu can swap the i’t…
Stack is a basic data structure. Where 3 operation can be done- Push: You can push object to the stack Pop: You can pop the object to the stack Top: You can check the value of the top object. For further details you can get idea here ( if you really…
参考:http://hzwer.com/4361.html 坐标开long long,inf开大点 先曼哈顿转切比雪夫(x+y,x-y),距离就变成了max(x',y'): 先按x排序,维护两个指针,指针内区间的x差总是<=c: 用一个multiset维护指针内元素,按y排序,每次加的时候找这个点y的前驱后继,判断是否符合y的差<=c(x已经通过左指针右移eraser完成了),是则加入并查集,像生成树那样的做法: 然后统计一下并查集的根个数和maxsize即可 转切比雪夫是重点! #inclu…
C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a re…
 感觉自己的解法很复杂,写了一大堆代码 但核心是从小到大枚举每个元素的值,然后把<=当前元素的值进行合并,由于这个过程是单调的,所以可以直接将新的元素合并到旧的并查集里去 维护并查集的同时维护每个集合的大小size,将size放在multiset 里然后判断每个块的大小是否相同,如果相同则更新答案 #include<bits/stdc++.h> #include<set> using namespace std; #define maxn 200005 int a[maxn]…
思路: 利用并查集/DFS都可以处理连通问题. PS:注意Find()查找值和pre[]值的区别. #include<bits/stdc++.h> using namespace std; const int N=1e3+10; int val[N]; int pre[N],n,m; vector<int>xs,ans; int Find(int x) { int r=x; while(pre[r]!=r) r=pre[r]; int i=x,j; while(pre[i]!=r)…
[题目分析] 区间开方+区间求和. 由于区间开方次数较少,直接并查集维护下一个不是1的数的位置,然后暴力修改,树状数组求和即可. 这不是BZOJ上上帝造题7分钟嘛 [代码] #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long long using namespace std; l…
题目描述: Taplu and Abhishar loved playing scrabble. One day they thought of inventing a new game using alphabet tiles. Abhishar wrote a string using tiles and gave a set of pairs (i,j) to Taplu. Pair “i, j” (0 based indexing) means that Taplu can swap t…