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. DELL vostro V5460 装mSATA 半高SSD硬盘后装win8.1系统

    1.介绍 DELL vostro V5460的超极本性能虽然不是那么好,但的确是我觉得样子最好看的一款.满足了,轻,薄.如果是红色的,则很适合女生用. 2.缺点 这款笔记本最大的缺点,就是有的无线网卡 ...

  2. Appium常用的API函数

    在学习应用一个框架之前,应该了解一下这个框架的整体结构或是相应的API函数.这篇文章还不错:http://blog.sina.com.cn/s/blog_68f262210102vzf9.html,就 ...

  3. UE4 Windows平台部署游戏到IOS 第二部分

    点击加号后会出来如下截图 勾选上红色单选框处(因为这个我已经申请过了所以是灰色),然后continue到后面会出现下图 选择一个之前我提到申请证书会用的的那个.csr后缀文件夹,完成以后就可以下载证书 ...

  4. JS和Android交互

    //本地webview写法 webview = (WebView) findViewById(R.id.webview); webview.loadUrl("http://192.168.1 ...

  5. 最近这两天看了关于H5游戏开发的一个教程,实践很短暂,看了很多理论的东西,现在呢也只是想回忆回忆关于EUI的部分知识吧

    首先我了解了什么是Egret: Egret中文就是白鹭的意思,Egret是一套H5游戏开发的软件.(纯粹属于个人理解) 其次我对以下几款软件的相关知识做了些了解: Egret Engine(引擎),E ...

  6. 转:WebService通用接口

    看到许多中小项目的webservice接口的源代码,不禁有个吐槽的冲动.除了会用CXF,Axis2等神级框架,其他的懒得动了,都是Ctrl+V,Ctrl+C,把其他模块的Request,Respons ...

  7. NSLog 自定义 屏蔽

    1.如何自定义NSLog呢? 直接在工程的XXX_Prefix.pch中加入以下语句(就相当于在全局中定义了)#define NSLog NSLog(@"#%s##%d#",str ...

  8. Linux Command Line 笔记(1)

    Yunduan CUI graphical user interfaces make easy tasks easy, while command line interfaces make diffi ...

  9. NLP概述

    1,词法分析 待续 2,文本分类 文本表示: 重点是贝叶斯模型:二项表示法和多项表示法.(向量维度为词库大小,一个是01,一个是频次).模型重点在于化后验为先验. 还有其他模型:机器学习模型,分布式模 ...

  10. select,poll,epoll区别

    select:忙轮询,一直在轮询,效率跟链接数成反比,资源限制 poll:轮询,不用一直轮询,有事件触发时轮询,资源限制 epoll:有事件触发时直接通知复杂度O(1)