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 <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int ,pii> p3;
//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B; A <= C; ++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const double PI=acos(-1.0); template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /*-----------------------show time----------------------*/
const int maxn = 2e5+;
ll a[maxn],vis[maxn];
set<pll>s;
int main(){
int n;
scanf("%d", &n);
for(int i=; i<=n; i++){
scanf("%lld", &a[i]);
s.insert(pll(a[i],i));
} while(s.size() > ){
pll t = *s.begin();
s.erase(s.begin());
pll x = *s.begin();
s.erase(s.begin());
// cout<<t.se << " "<<x.se<<endl;
if(x.fi == t.fi){
vis[t.se] = ;
x.fi = x.fi + x.fi;
a[x.se] = x.fi;
}
// debug(x.fi);
s.insert(x);
}
int cnt = ;
for(int i=; i<=n; i++)if(vis[i]==)cnt++;
printf("%d\n", cnt);
for(int i=; i<=n; i++){
if(!vis[i])printf("%lld " , a[i]);
}
printf("\n");
}

CF962D

Educational Codeforces Round 42 D. Merge Equals (set + pll)的更多相关文章

  1. Educational Codeforces Round 42 (Rated for Div. 2) D. Merge Equals

    http://codeforces.com/contest/962/problem/D D. Merge Equals time limit per test 2 seconds memory lim ...

  2. D Merge Equals Educational Codeforces Round 42 (Rated for Div. 2) (STL )

    D. Merge Equals time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

  3. Educational Codeforces Round 42 (Rated for Div. 2)

    A. Equator(模拟) 找权值的中位数,直接模拟.. 代码写的好丑qwq.. #include<cstdio> #include<cstring> #include< ...

  4. D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))

    模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include < ...

  5. Educational Codeforces Round 42 (Rated for Div. 2) E. Byteland, Berland and Disputed Cities

    http://codeforces.com/contest/962/problem/E E. Byteland, Berland and Disputed Cities time limit per ...

  6. Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges

    http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...

  7. Educational Codeforces Round 42 (Rated for Div. 2) C

    C. Make a Square time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. Educational Codeforces Round 42 (Rated for Div. 2) A

    A. Equator time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  9. C Make a Square Educational Codeforces Round 42 (Rated for Div. 2) (暴力枚举,字符串匹配)

    C. Make a Square time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

随机推荐

  1. Linux基本操作及安装(部分)

    1.分别用cat \tac\nl三个命令查看文件/etc/ssh/sshd_config文件中的内容,   并用自己的话总计出这三个文档操作命令的不同之处? [root@localhost ~]# c ...

  2. linux文本编辑vim命令

    1.Vim Vim  是一个功能强大的全屏幕文本编辑器,是 Linux/UNIX 上最常用的文本编辑器,它的作用是建立.编辑.显示文本文件. Vim 没有菜单,只有命令 2.Vim 工作模式 3.插入 ...

  3. sql server 2008 外键的级联操作

    问题提出:现在我有三张表,学生Student,课程Course,成绩SC 1.  学生表Student,主键是学号Sno 2.  课程Course,主码是课程号Cno 3.  成绩SC,主码是Sno和 ...

  4. 配置VNC并远程控制服务器(电脑)

    先象征性介绍一下: VNC (Virtual Network Console)是虚拟网络控制台的缩写, 它是一款基于 UNIX 和 Linux 操作系统的优秀.免费.开源的远程控制工具软件. 然后开始 ...

  5. css常用代码块

    顶部固定导航栏 | css position: fixed; top: 0; left: 0; z-index: 9999; width: 100%; height: 48px; border-top ...

  6. IntelliJ IDEA 激活(最新)

    注:此文以 Mac 为例,Windows 的激活方法也大同小异.如果不差钱的话,建议购买正版! 1.下载安装 直接通过下面的链接到官网下载最新的 Ultimate 版本即可: https://www. ...

  7. 理解-NumPy

    # 理解 NumPy 在这篇文章中,我们将介绍使用NumPy的基础知识,NumPy是一个功能强大的Python库,允许更高级的数据操作和数学计算. # 什么是 NumPy? NumPy是一个功能强大的 ...

  8. Mysql: 图解 inner join、left join、right join、full outer join、union、union all的区别

    转载来源 对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚. ...

  9. 【Node/JavaScript】论一个低配版Web实时通信库是如何实现的( WebSocket篇)

    引论 simple-socket是我写的一个"低配版"的Web实时通信工具(相对于Socket.io),在参考了相关源码和资料的基础上,实现了前后端实时互通的基本功能 选用了Web ...

  10. net core Webapi基础工程搭建(七)——小试AOP及常规测试_Part 2

    目录 前言 引入 自定义属性 测试 小结 前言 前一篇讲到了中间层的使用,可能不是那么AOP,今天主要来说下一个轻量级的AOP第三方类库AspectoCore. 简单介绍下这个类库,AspectCor ...