Another fun Greedy problem to work on: we simply go from first to second last person, as long someone is odd, we distribute bread to her and her next.

#include <vector>
#include <iostream> using namespace std; int main()
{
int N;
cin >> N;
vector<int> B(N);
for(int B_i = ;B_i < N;B_i++){
cin >> B[B_i];
} int cnt = ;
for(int i = ; i < N - ; i ++)
{
if(B[i] % )
{
B[i] ++;
B[i+]++;
cnt += ;
}
} if(B.back() % )
cout << "NO" << endl;
else
cout << cnt << endl; return ;
}

HackerRank "Fair Rations"的更多相关文章

  1. LA 3231 - Fair Share

    You are given N processors and M jobs to be processed. Two processors are specified to each job. To ...

  2. Codeforces CF#628 Education 8 F. Bear and Fair Set

    F. Bear and Fair Set time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  3. java线程 公平锁 ReentrantLock(boolean fair)

    一.公平锁 1.为什么有公平锁 CPU在调度线程的时候是在等待队列里随机挑选一个线程,由于这种随机性所以是无法保证线程先到先得的(synchronized控制的锁就是这种非公平锁).但这样就会产生饥饿 ...

  4. Fair Scheduler 队列设置经验总结

    Fair Scheduler 队列设置经验总结 由于公司的hadoop集群的计算资源不是很充足,需要开启yarn资源队列的资源抢占.在使用过程中,才明白资源抢占的一些特点.在这里总结一下. 只有一个队 ...

  5. 日常小测:颜色 && Hackerrank Unique_colors

    题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...

  6. Fair Scheduler中的Delay Schedule分析

    延迟调度的主要目的是提高数据本地性(data locality),减少数据在网络中的传输.对于那些输入数据不在本地的MapTask,调度器将会延迟调度他们,而把slot分配给那些具备本地性的MapTa ...

  7. HackerRank "Square Subsequences" !!!

    Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...

  8. HackerRank "Minimum Penalty Path"

    It is about how to choose btw. BFS and DFS. My init thought was to DFS - TLE\MLE. And its editorial ...

  9. HackerRank "TBS Problem" ~ NPC

    It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...

随机推荐

  1. OpenSuse 中目录中文路径改为英文路径

    在很多发行版中可以通过: export LANG=en_US xdg-user-dirs-gtk-update 将主目录的英文路径名改为中文,然后恢复: export LANG=zh_CN 但是Ope ...

  2. hexo环境变量的配置问题

    因为一些个人原因,想尝试在github上用hexo搭建一个博客,于是用npm安装,安装完成之后却一直无法确认hexo的版本问题,cmd中也一直提示hexo -v 不是有效的命令行,在重装了几次Node ...

  3. Android 学习第14课,Android 布局

    布局分4种: 1. LinearLayout (线性布局) file:///H:/tool/01/Android/android-sdk-windows/docs/guide/topics/ui/la ...

  4. 嵌入式linux应用程序移植方法总结

    嵌入式linux应用程序移植方法总结 前段时间一直在做openCapwap的移植和调试工作,现在工作已接近尾声,编写本文档对前段工作进行一个总结,分享下openCapwap移植过程中的经验和感悟.江浩 ...

  5. 项目中Gradle使用总结

    一.配置Gradle使用Maven仓库 项目过程中,我们可能会遇到maven的本地库和gradle使用的maven本地库,不是同一个库.现在总结下怎么配置使得maven和gradle都使用相同的mav ...

  6. S2SH+mysql-软件开发实际部署问题-8个小时后提示MYSQL数据库无法连接

    type Exception report message description The server encountered an internal error () that prevented ...

  7. myeclipse打war包时,报错security alert integrity check error

    今天在用myeclipse打包项目时,出现如下图的提示: 在网上查找了一下原因,主要是由于Jar包不符合所导致的.解决办法如下: 将com.genuitec.eclipse.export.wizard ...

  8. URL参数为url,获取不到部分参数问题

    url1中的参数含有url2,在页面上获取url时发现url后面跟的参数获取不到,其实是浏览器把url2中&后的参数作为url1的参数来处理了. 如:http://www.ilcng.com/ ...

  9. 第六章第一个linux个程序:统计单词个数

    第六章第一个linux个程序:统计单词个数 从本章就开始激动人心的时刻——实战,去慢慢揭开linux神秘的面纱.本章的实例是统计一片文章或者一段文字中的单词个数.  第 1 步:建立 Linu x 驱 ...

  10. toUnsignedString详解

    /** * All possible chars for representing a number as a String */ final static char[] digits = { '0' ...