Codeforces 962D - Merge Equals】的更多相关文章

链接: http://codeforces.com/problemset/problem/962/D 题意: 给出一个整数序列.选择其中最小且出现两次(或以上)的数,把最左边的两个从序列中移除,然后把它们的和放到它们的后面第一位.不断重复上述过程,直到序列中的每个数都是唯一的.输出最后的序列. 分析: 如果在数a的前面有一个可以跟a合并的数b,则b一定是唯一的.否则,b要先跟其他等值的数合并.这样,我们只需要从左到右依次加入每个数,不断维护当前序列的唯一性即可.方法是用map记录前面每个数值的唯…
题意 : 给出一个序列,然后每次将重复出现的元素进行求和合并(若有多个,则优先取最小的进行合并),若某重复元素有很多,那么取最左边的那两个进行合并且合并后元素位于原来右边元素的位置,例如 3 2 6 2 2 这里 2 是重复元素,取最左边的两个 2 进行一次求和合并,合并后将变成 4 ,且这个 4 的位置位于较右边的 2 的位置,即序列变成 3 6 4 2.进行这样的操作,直到没有元素重复为止,输出最终序列. 分析 :  考察模拟能力 首先注意到,输出最后的序列 只需要知道各个元素的相对位置即可…
http://codeforces.com/contest/962/problem/D D. Merge Equals time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array of positive integers. While there are at least two equal…
D. Merge Equals time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array of positive integers. While there are at least two equal elements, we will perform the following oper…
D. Merge Equals time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given an array of positive integers. While there are at least two equal elements, we will perform the following operatio…
模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include <set> #define N 150005 using namespace std; typedef long long Int; ; map<long long, set<int> > mapp; long long a[N]; int main() { int n; cin…
CF962D 题意: 给定一个数列,对于靠近左端的两个相同大小的值x可以合并成一个点.把x 乘以2 放在第二个点的位置,问最后的数列大小和每个位子的值. 思路: 利用set 配上 pair 就行了,感觉很巧妙,每次取出前两个pll  t1,t2. 如果 t1.first != t2.first ,把t2直接重新放入set中,否则,把t2.first * 2并更新t2.second 位子,把t2放入到set中.(这么说好像优先队列也可以) #include <iostream> #include…
题目链接:http://codeforces.com/problemset/problem/1176/B 题意:给定序列,任意俩个元素可以相加成一个元素,求序列元素能被3整除的最大数量. 思路: 对于所有元素进行 模3 的预处理,然后 贪心 余数1 和 余数2 的配对,剩下的 3个 一组配对. AC代码: #include<bits/stdc++.h> using namespace std; int main() { int t; ]; cin >> t; while(t--)…
题目链接 n个数m个询问, 每次询问输出给定区间中任意两个相同的数的最近距离. 先将询问读进来, 然后按r从小到大排序, 将n个数按顺序插入, 并用map统计之前是否出现过, 如果出现过, 就更新线段树. 如果当前的i等于某个询问的r, 那么就查询, 具体看代码. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm&…
题解: 傻逼题 直接从左向右扫描每个点作为右端点 然后单点修改区间查询就行了 另外一种更直观的做法就是$(i,j)$之间产生了$(j-i)$ 于是变成矩形查最大值,kd-tree维护 代码: #include <bits/stdc++.h> #define rint register int #define IL inline #define rep(i,h,t) for (int i=h;i<=t;i++) #define dep(i,t,h) for (int i=t;i>=h…