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. asp.net页面事件执行顺序

    转自http://www.cnblogs.com/hnlyh/articles/4230388.html C#代码 using System; using System.Data; using Sys ...

  2. Java随笔三

    1.接口: 1)接口不是类,不能使用new运算符实例化一个接口,而是对类的一组需求描述,这些类要遵循接口描述的统一格式进行定义.个人感觉像C语言中的函数在头文件中的预先声明,但是包含了一些类的特点,比 ...

  3. Android ——单元测试

    什么是单元测试 首先需要介绍一下什么是单元测试.很多人像我一样,本科并不是计算机专业出身的,如果在职的公司不要求做单元测试的话,可能对这个词并没有一个确切的概念.而即使是计算机专业出身,如果毕业以后写 ...

  4. CPU指令集

    cpu作为一台电脑中的核心,它的作用是无法替代的.而cpu本身只是在块硅晶片上所集成的超大规模的集成电路,集成的晶体管数量可达到上亿个,是由非常先进复杂的制造工艺制造出来的,拥有相当高的科技含量. C ...

  5. 帝国cms内容批量替换

    方法一:栏目-其他相关-批量替换字段值 方法二:通过sql替换           UPDATE phome_ecms_news SET body=REPLACE(body,'原来','现在')

  6. 105 董婷婷 第二次Sprint总结

    总结: 第二次冲刺结束了,这次冲刺的主要任务是建立数据库.项目进行到现在也基本定型了,满满的成就感啊.经过一段时间的合作,团队成员间的默契大大提高,还有最后一次冲刺,队友们,加油哦!

  7. 一些新的ideas

    k-means可以在不同的聚类点间加入计算该方向类内方差的方法改进,可以获得更好的效果: 可以通过爬虫方法在facebook上爬取与happy.sad相关的图片进行图片情感分类,并通过语义分析的方法提 ...

  8. PHP character garbled

    MySql  控制台查询时出现乱码 Database&Table 的字符集 于Mysql控制台显示的字符集不一样 右键单击mysql控制台边框  单击属性  查看当前代码页的字符集模式是否于数 ...

  9. React(JSX语法)----JSX拼写

    注意:For DOM differences,such as the inline style attribute,check here. // bad: it displays "FIrs ...

  10. CSS3+JS切割轮播图

    以下说明数据,是指有4张图片的轮播图,分别切割成4张. 首先,做成单张切换的立体效果,即通过旋转,确定四张图片的位置,分别是一个立方体的上下前后的图片翻转移动角度. .box ul li:nth-ch ...