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. Java SCP copy local file to remote implementation

    最近做的项目中,有一个小需求,需要通过SCP把本地文件copy到远程服务器.查了好多资料,最终解决方案简单快速,分享一下. 在这里,需要用到4个jar包,分别是ant-jsch.jar,ant-lau ...

  2. UE4 VR GUI实现 参考(UMG AND VR)

    Note:4.13以后版本VR UI采用 WidgetComponent + WidgetInteractionComponent可轻松实现交互 Blueprint Demo: https://for ...

  3. NSOperation的几种使用方式

    1.NSInvocationOperation 创建NSInvocationOperation对象 - (id)initWithTarget:(id)target selector:(SEL)sel ...

  4. Android TextView设置多彩文字

    在应用开发中时常会遇到需要在一段文字中插入几个不一样颜色文字的需求; 以前本人都是用多个TextView拼起来,不仅感觉很蠢,操作起来也蛮恶心; 直到接触到了SpannableStringBuilde ...

  5. Direct3D 10学习笔记(二)——计时器

    本篇将简单整理Direct3D 10的计时器实现,具体内容参照< Introduction to 3D Game Programming with DirectX 10>(中文版有汤毅翻译 ...

  6. 完成Matrix丶Kingdom PPT后的感想

    这次Presentation是我在这节课的第一次上台演讲,让我感悟良多. 具体对我的PPT有兴趣的朋友可以call我,我会共享给大家. 这次老师布置的任务对我而言很有意义.首先,我作为最后一组,我欣赏 ...

  7. js完美身份证验证

    /*根据[中华人民共和国国家标准 GB 11643-1999]中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本体码和一位数字校验码组成.排列顺序从左至右依次为:六位数字地址码,八位数 ...

  8. [驱动开发] struct _LDR_DATA_TABLE_ENTRY

    @Windows XP Professional Service Pack 3 (x86) (5.1, Build 2600) lkd> dt -b _LDR_DATA_TABLE_ENTRY ...

  9. Newtonsoft.Json 处理多态类型的反序列化

    Newtonsoft.Json的序列化和反序列化很成熟也很好用, 最近在处理多态类型的反序列化中遇到了问题, 反序列化后只能到基类,而得不到也不能转换到子类.从网上查询了一番后,需要写一个创建类型的C ...

  10. Oracle笔记2-数据库设计

    数据库的设计 软件开发的流程:立项->需求分析->概要设计->详细设计->实现->测试->交付->维护 [含数据库设计] 通过需求分析,就可以抽取出关键业务中 ...