Greedy - though simple, but fun!

  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7. int n1;
  8. int n2;
  9. int n3;
  10. cin >> n1 >> n2 >> n3;
  11. long long l1 = , l2 = , l3 = ;
  12. vector<int> h1(n1);
  13. for(int h1_i = ;h1_i < n1;h1_i++){
  14. cin >> h1[h1_i];
  15. l1 += h1[h1_i];
  16. }
  17. vector<int> h2(n2);
  18. for(int h2_i = ;h2_i < n2;h2_i++){
  19. cin >> h2[h2_i];
  20. l2 += h2[h2_i];
  21. }
  22. vector<int> h3(n3);
  23. for(int h3_i = ;h3_i < n3;h3_i++){
  24. cin >> h3[h3_i];
  25. l3 += h3[h3_i];
  26. }
  27.  
  28. int i1 = , i2 = , i3 = ;
  29. while(!(l1 == l2 && l2 == l3))
  30. {
  31. // which stack is highest now?
  32. int maxi = ;
  33. int maxl = l1;
  34. if(maxl < l2)
  35. {
  36. maxi = ;
  37. maxl = l2;
  38. }
  39. if(maxl < l3)
  40. {
  41. maxi = ;
  42. maxl = l3;
  43. }
  44.  
  45. //
  46. switch(maxi)
  47. {
  48. case :
  49. l1 -= h1[i1++];
  50. break;
  51. case :
  52. l2 -= h2[i2++];
  53. break;
  54. case :
  55. l3 -= h3[i3++];
  56. break;
  57. }
  58.  
  59. if(!l1 || !l2 || !l3)
  60. {
  61. l1 = l2 = l3 = ;
  62. }
  63. }
  64. cout << l1 << endl;
  65. return ;
  66. }

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. GGXX的卡通渲染实现 真的好变态......

    最近在youtube上看了GDC,学了很多东西,最让我震撼的就是ggxx的卡通渲染了.感慨一下,想要用3D做出二次元的效果,真的不容易.现记录一些要点: 1)不要使用normal map来做cel-s ...

  2. NOIP 考前 Tarjan复习

    POJ 1236 给定一个有向图,求: 1) 至少要选几个顶点,才能做到从这些顶点出发,可以到达全部顶点 2) 至少要加多少条边,才能使得从任何一个顶点出发,都能到达全部顶点 第一个就是缩点之后有多少 ...

  3. Java随笔四---Java异常

    1.throw语句:Java编译器在执行throw语句时,会立即停止常规的程序执行,开始寻找能够捕获或处理异常的异常处理程序: 2.异常处理程序使用try/catch/finally编写. 3.如果当 ...

  4. Cruehead.1

    查壳   没有 我拖 alt+F9 到上面        入口处   下断 关键跳      略过   就没了 要实现 强暴  直接过... 仔细来看看... 那两个调用   都下断   看看  判断 ...

  5. codeforces 724D(贪心)

    题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...

  6. HDU4010 (动态树)

    Problem Query on The Trees 题目大意 给一棵树,有点权,要求维护4种操作. 操作1:加一条边. 操作2:删一条边. 操作3:将一条路径上的点权增加w. 操作4:询问一条路径上 ...

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

  8. 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 ...

  9. python sproto支持64位有符号整数

    小伙伴需要64位整数做物品的id,之前python sproto的判断有问题,写篇日志记录一下. 之前有问题的代码是这样的: if (!PyInt_Check(data)) { PyErr_SetOb ...

  10. Halcon pick_and_place_scara_stationary_cam.hdev程序学习

    此示例显示如何基于由SCARA手眼校准确定的校准信息,使用SCARA机器人执行拾取和放置应用程序. 在第一步骤中,根据模型图像定义形状模型. 然后,基于该形状模型,在每个图像中搜索对象. 对于一个选定 ...