HackerRank "Equal Stacks"
Greedy - though simple, but fun!
- #include <vector>
- #include <iostream>
- using namespace std;
- int main(){
- int n1;
- int n2;
- int n3;
- cin >> n1 >> n2 >> n3;
- long long l1 = , l2 = , l3 = ;
- vector<int> h1(n1);
- for(int h1_i = ;h1_i < n1;h1_i++){
- cin >> h1[h1_i];
- l1 += h1[h1_i];
- }
- vector<int> h2(n2);
- for(int h2_i = ;h2_i < n2;h2_i++){
- cin >> h2[h2_i];
- l2 += h2[h2_i];
- }
- vector<int> h3(n3);
- for(int h3_i = ;h3_i < n3;h3_i++){
- cin >> h3[h3_i];
- l3 += h3[h3_i];
- }
- int i1 = , i2 = , i3 = ;
- while(!(l1 == l2 && l2 == l3))
- {
- // which stack is highest now?
- int maxi = ;
- int maxl = l1;
- if(maxl < l2)
- {
- maxi = ;
- maxl = l2;
- }
- if(maxl < l3)
- {
- maxi = ;
- maxl = l3;
- }
- //
- switch(maxi)
- {
- case :
- l1 -= h1[i1++];
- break;
- case :
- l2 -= h2[i2++];
- break;
- case :
- l3 -= h3[i3++];
- break;
- }
- if(!l1 || !l2 || !l3)
- {
- l1 = l2 = l3 = ;
- }
- }
- cout << l1 << endl;
- return ;
- }
HackerRank "Equal Stacks"的更多相关文章
- HackerRank - candies 【贪心】
HackerRank - candies [贪心] Description Alice is a kindergarten teacher. She wants to give some candie ...
- Hackerrank - The Grid Search
https://www.hackerrank.com/challenges/the-grid-search/forum 今天碰见这题,看见难度是Moderate,觉得应该能半小时内搞定. 读完题目发现 ...
- Hackrank Equal DP
Christy is interning at HackerRank. One day she has to distribute some chocolates to her colleagues. ...
- Infix to Prefix conversion using two stacks
Infix : An expression is called the Infix expression if the operator appears in between the operands ...
- [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二
Given a non-empty integer array, find the minimum number of moves required to make all array element ...
- [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等
Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...
- [LeetCode] Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- [LeetCode] Implement Queue using Stacks 用栈来实现队列
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...
- Equal Sides Of An Array
参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...
随机推荐
- GGXX的卡通渲染实现 真的好变态......
最近在youtube上看了GDC,学了很多东西,最让我震撼的就是ggxx的卡通渲染了.感慨一下,想要用3D做出二次元的效果,真的不容易.现记录一些要点: 1)不要使用normal map来做cel-s ...
- NOIP 考前 Tarjan复习
POJ 1236 给定一个有向图,求: 1) 至少要选几个顶点,才能做到从这些顶点出发,可以到达全部顶点 2) 至少要加多少条边,才能使得从任何一个顶点出发,都能到达全部顶点 第一个就是缩点之后有多少 ...
- Java随笔四---Java异常
1.throw语句:Java编译器在执行throw语句时,会立即停止常规的程序执行,开始寻找能够捕获或处理异常的异常处理程序: 2.异常处理程序使用try/catch/finally编写. 3.如果当 ...
- Cruehead.1
查壳 没有 我拖 alt+F9 到上面 入口处 下断 关键跳 略过 就没了 要实现 强暴 直接过... 仔细来看看... 那两个调用 都下断 看看 判断 ...
- codeforces 724D(贪心)
题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...
- HDU4010 (动态树)
Problem Query on The Trees 题目大意 给一棵树,有点权,要求维护4种操作. 操作1:加一条边. 操作2:删一条边. 操作3:将一条路径上的点权增加w. 操作4:询问一条路径上 ...
- Vector Calculus
Vector Fields Vector Function F(x,y,...)=P(x,y)i + Q(x,y)j + ... = <P(x,y), Q(x,y), ...> F=Pi ...
- Linux系统启动错误 contains a file system with errors, check forced解决方法
/dev/sda1 contains a file system with errors, check forced./dev/sda1: Inodes that were part of a cor ...
- python sproto支持64位有符号整数
小伙伴需要64位整数做物品的id,之前python sproto的判断有问题,写篇日志记录一下. 之前有问题的代码是这样的: if (!PyInt_Check(data)) { PyErr_SetOb ...
- Halcon pick_and_place_scara_stationary_cam.hdev程序学习
此示例显示如何基于由SCARA手眼校准确定的校准信息,使用SCARA机器人执行拾取和放置应用程序. 在第一步骤中,根据模型图像定义形状模型. 然后,基于该形状模型,在每个图像中搜索对象. 对于一个选定 ...