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. Java的CLASSPATH,趁还没忘赶紧写点

    咳咳,睡眠不足加上年龄增长,真的赶脚记忆力不行啦. 接触Java以来,对于环境配置就是按照网上的教程,一路复制粘贴,也没啥想法; 最近决定啃啃ThinkInJava,没看两章就看到这CLASSPATH ...

  2. 纠结attr(),prop()

    刚刚看博客无意中看到attr()和prop()的区别,回头就去翻了一下手册,感觉手册上写的过于简单,不能很清晰的分辨出两者的区别,两者的参数用法都是高度相似. attr():设置或返回被选元素的属性值 ...

  3. 12、c#中事务及回滚

    public void UpdateContactTableByDataSet(DataSet ds, string strTblName) { try { SqlDataAdapter myAdap ...

  4. 黑马程序员:Java编程_IO流

    =========== ASP.Net+Android+IOS开发..Net培训.期待与您交流!=========== 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设 ...

  5. 蓝牙-HCI错误码列表

    错误码定义: /* Success code */ #define HCI_SUCCESS 0x00 /* Possible error codes */ #define HCI_UNKNOWN_HC ...

  6. php实现的笛卡儿积

    之前在网上找到一个大牛写的版本(网址已经记不得了..),如下 function Descartes1() { //Cartesian product of arrays or strings or s ...

  7. import pysam 出错解决办法

    安装pysam后,import之,结果,出现报错: Library not loaded: libcurl.4.dylib 尝试很多办法,最终发现应当这样解决: # 首先重装curl brew ins ...

  8. GPU 加速NLP任务(Theano+CUDA)

    之前学习了CNN的相关知识,提到Yoon Kim(2014)的论文,利用CNN进行文本分类,虽然该CNN网络结构简单效果可观,但论文没有给出具体训练时间,这便值得进一步探讨. Yoon Kim代码:h ...

  9. Linux 中断处理浅析

    最近在研究异步消息处理, 突然想起linux内核的中断处理, 里面由始至终都贯穿着"重要的事马上做, 不重要的事推后做"的异步处理思想. 于是整理一下~ 第一阶段--获取中断号 每 ...

  10. 莱卡旗下旗下首台全片幅无反相机 Leica SL 抵港,吐槽下

    http://cn.engadget.com/2015/11/18/leica-sl-hk-hands-on/#continued 单机+单镜头=7.5W¥,如果再来个定焦共10W¥+:有心杀贼,无力 ...