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"的更多相关文章

  1. HackerRank - candies 【贪心】

    HackerRank - candies [贪心] Description Alice is a kindergarten teacher. She wants to give some candie ...

  2. Hackerrank - The Grid Search

    https://www.hackerrank.com/challenges/the-grid-search/forum 今天碰见这题,看见难度是Moderate,觉得应该能半小时内搞定. 读完题目发现 ...

  3. Hackrank Equal DP

    Christy is interning at HackerRank. One day she has to distribute some chocolates to her colleagues. ...

  4. Infix to Prefix conversion using two stacks

    Infix : An expression is called the Infix expression if the operator appears in between the operands ...

  5. [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 ...

  6. [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 ...

  7. [LeetCode] Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  8. [LeetCode] Implement Queue using Stacks 用栈来实现队列

    Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...

  9. Equal Sides Of An Array

    参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...

随机推荐

  1. 实现Launcher默认壁纸、选择壁纸定制化功能

    需求功能说明:     该定制需求为在系统中增加一个新的分区如myimage,用以实现存放定制资源.例如在myimage下新建wallpaper文件夹用于存放定制的墙纸图片资源,当Launcher加载 ...

  2. repo upload上传提交时发生remote rejected异常

    部分关键异常内容为: ...... remote:ERROR:committer email address %%%%%% remote:ERROR:does not match your user ...

  3. css width height

    css 中body 的默认宽度是100%,但是默认高度为0px

  4. windows核心编程---第八章 使用内核对象进行线程同步

    使用内核对象进行线程同步. 前面我们介绍了用户模式下线程同步的几种方式.在用户模式下进行线程同步的最大好处就是速度非常快.因此当需要使用线程同步时用户模式下的线程同步是首选. 但是用户模式下的线程同步 ...

  5. 安装go语言,配置环境及IDE,只需3步

    安装go语言,配置环境及IDE,只需3步 ( 欢迎加入go语言群: 218160862 , 群内有实践) 第1.下载 go压缩包,解压   ,如果你是window系统,请选择go1.5.windows ...

  6. 使用for循环遍历数组

    package review20140419;/* * 遍历数组 */public abstract class Test1 {    //程序入口    public static void mai ...

  7. 实现PageProcessor

    4.1 实现PageProcessor 这部分我们直接通过GithubRepoPageProcessor这个例子来介绍PageProcessor的编写方式.我将PageProcessor的定制分为三个 ...

  8. 在博文中嵌入Javascript代码

    今天吃饭时无聊,突然想到Markdown除了兼容HTML会不会也兼容Javascript,于是博文里除了码文插音乐还可以干点更好玩的事儿了,可以自动修改markdown文件本身,比如说自动修改从Git ...

  9. MySql 中游标,事务,终止存储过程方法总结

    最近在项目开发中,有段逻辑处理,需要在网站,app,后台分别运行,这样给后期的维护带来了很大的不方便,容易遗漏app端或者后台,所以讲java代码转换成存储过程,把逻辑处理写在了mysql端,其中遇到 ...

  10. 11个提问频率最高的PHP面试题

    问题:请用最简单的语言告诉我PHP是什么? 回答:PHP全称:Hypertext Preprocessor,是一种用来开发动态网站的服务器脚本语言. 问题:什么是MVC? 回答:MVC由Model(模 ...