Codeforces 962D Merge Equals ( 模拟 )】的更多相关文章

题意 : 给出一个序列,然后每次将重复出现的元素进行求和合并(若有多个,则优先取最小的进行合并),若某重复元素有很多,那么取最左边的那两个进行合并且合并后元素位于原来右边元素的位置,例如 3 2 6 2 2 这里 2 是重复元素,取最左边的两个 2 进行一次求和合并,合并后将变成 4 ,且这个 4 的位置位于较右边的 2 的位置,即序列变成 3 6 4 2.进行这样的操作,直到没有元素重复为止,输出最终序列. 分析 :  考察模拟能力 首先注意到,输出最后的序列 只需要知道各个元素的相对位置即可…
链接: http://codeforces.com/problemset/problem/962/D 题意: 给出一个整数序列.选择其中最小且出现两次(或以上)的数,把最左边的两个从序列中移除,然后把它们的和放到它们的后面第一位.不断重复上述过程,直到序列中的每个数都是唯一的.输出最后的序列. 分析: 如果在数a的前面有一个可以跟a合并的数b,则b一定是唯一的.否则,b要先跟其他等值的数合并.这样,我们只需要从左到右依次加入每个数,不断维护当前序列的唯一性即可.方法是用map记录前面每个数值的唯…
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…
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard input output: standard output Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships…
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U'…
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人只能打招呼一次). 例: 输入:31 1 105 8 29 9 10 输出: 2 1 1 解题思路:先按行走的开始时刻排下序,然后直接模拟判断和比他后出现的人是否可以相遇. 第一步判断前面那个人在未走完前,下一人会出现,若不出现,直接break.然后就计算当下一个人出现的时刻,前一个人的位置,然后又…