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. kylin Retrieving hive dependency...

    由于公司环境配置hive默认连接hiveserver2 ,不管hive cli 还是beeline cli都默认使用beeline cli,连接hive需要输入账号密码; 启动kylin 时会Retr ...

  2. SQL和NoSQL的区别

    一.概念 SQL (Structured Query Language) 数据库,指关系型数据库.主要代表:SQL Server,Oracle,MySQL(开源),PostgreSQL(开源). No ...

  3. Java +支付宝 +接入+最全+最佳-实战-demo

    一.支付宝配置: 1.需要在支付宝商户平台购买支付的产品并开通支付. 2.购买支付产品登录支付宝:https://auth.alipay.com/login/index.htm 3.登录之后首页点击查 ...

  4. 喜大普奔 | 微信小程序支持PC端打开了

    微信小程序可以在PC端打开啦 微信PC版发布了v2.7.0测试版,其中一个重磅的功能就是:支持打开聊天中分享的小程序 咖啡君这么喜欢尝鲜的人自然是在第一时间下载进行了体验 安装成功,会有功能更新说明 ...

  5. react-native-gesture-handler报错

    安装React Native第三方组件出现Task :react-native-gesture-handler:compileDebugJavaWithJavac FAILED报错,则使用jetifi ...

  6. 带你剖析WebGis的世界奥秘----点和线的世界

    前言 昨天写了好久的博文我没保存,今天在来想继续写居然没了,气死人啊这种情况你们见到过没,所以今天重新写,我还是切换到了HTML格式的书写上.废话不多说了,我们现在就进入主题,上周我仔细研究了WebG ...

  7. pythonday06数据类型(四)

    今日内容 1.集合 2内存相关 1.集合set 无序 无重复 v = {1,2,3,4,5,6,99,100} # 疑问:v = {} """ None int v1 = ...

  8. JavaWeb购物车

    一.类关系 最近又把JavaWeb方面的知识(Servlet.jsp等)过了一遍,发现以前还是接触的太窄太浅.加上才转到IntelliJ IDEA 上故而想用这个项目练练,就当熟悉熟悉IntelliJ ...

  9. IntelliJ IDEA提升效率开发插件必备

    工欲善其事,必先利其器,好的工具可以提升我们的开发效率,下面介绍几款个人觉得比较好的编辑器插件,不仅炫酷更重要可以提高你的工作效率. 本文是作者辛苦整理的16款插件,每个都是超级实用的,不好不介绍,相 ...

  10. 源码分析--dubbo服务端暴露

    服务暴露的入口方法是 ServiceBean 的 onApplicationEvent.onApplicationEvent 是一个事件响应方法,该方法会在收到 Spring 上下文刷新事件后执行服务 ...