当前位置:网站首页>Gym 101911c bacteria (minimum stack)
Gym 101911c bacteria (minimum stack)
2022-07-28 04:55:00 【gongyuandaye】
The question :n Elements , Choose two identical elements at a time , If there is no , Add a new , Then put the sum of the two numbers back into the original sequence , Ask if there is only one element left , And how many are added .
Answer key : The smallest pile
Just simulate the process of taking .
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<fstream>
#include<set>
#include<map>
#include<sstream>
#include<iomanip>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int maxn = 2e5 + 5;
int n, x;
ll a, b;
priority_queue<ll, vector<ll>, greater<ll> > q;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
q.push(x);
}
int ans = 0;
x = 0;
while (q.size()) {
++x;
if (x == 2 * maxn) {
ans = -1;
break;
}
a = q.top();
q.pop();
if (q.empty()) break;
b = q.top();
if (a == b) {
q.pop();
q.push(2ll * a);
}
else {
ans++;
q.push(2ll * a);
}
}
printf("%d\n", ans);
return 0;
}
边栏推荐
- Rendering process, how the code becomes a page (2)
- Jupyter notebook installation code prompt function
- 全方位分析STEAM和创客教育的差异化
- alter和confirm,prompt的区别
- scipy.stats.chi2
- 数据库故障容错之系统时钟故障
- Redis类型
- RT_ Use of thread mailbox
- Alibaba interview question [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
- RT based_ Distributed wireless temperature monitoring system of thread (I)
猜你喜欢

字符串0123456789abcdef,子串(非空且非同串本身)的个数是多少【杭州多测师】【杭州多测师_王sir】...

驾驭EVM和XCM的强大功能,SubWallet如何赋能波卡和Moonbeam
![[每日一氵]上古年代的 Visual Studio2015 安装](/img/b1/066ed0b9e93b8f378c89ee974163e5.png)
[每日一氵]上古年代的 Visual Studio2015 安装

Testcafe provides automatic waiting mechanism and live operation mode
![String 0123456789abcdef, what is the number of substrings (not empty and not the same string itself) [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]](/img/78/efe3d70a4bfe8ac0c9b58b54d02b00.png)
String 0123456789abcdef, what is the number of substrings (not empty and not the same string itself) [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]

Analysis of the reason why easycvr service can't be started and tips for dealing with easy disk space filling

你必需要了解的saas架构设计?

What SaaS architecture design do you need to know?

低代码是开发的未来吗?浅谈低代码平台

Automated test tool playwright (quick start)
随机推荐
Design and development of C language ATM system project
欧拉路/欧拉回路
Explain initialization list
100 lectures on Excel practical application cases (XI) - tips for inserting pictures in Excel
Research on the design of robot education in stem course
[Sylar] framework Chapter 22 auxiliary module
[high CPU consumption] software_ reporter_ tool.exe
ADB environment configuration
Odoo action analysis (action.client, action.act_window, action.server)
猿辅导技术进化论:助力教与学 构想未来学校
Special topic of APP performance design and Optimization - poor implementation affecting performance
Domain name (subdomain name) collection method of Web penetration
Leetcode 15. sum of three numbers
机器人教育在STEM课程中的设计研究
What should testers know about login security?
What is the reason why the easycvr national standard protocol access equipment is online but the channel is not online?
数据安全逐步落地,必须紧盯泄露源头
[Sylar] framework chapter -chapter10-address module
Gerrit operation - rollback a patch_ set
[Sylar] framework -chapter24- support business modularization