HackerRank "Fair Rations"
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"的更多相关文章
- LA 3231 - Fair Share
You are given N processors and M jobs to be processed. Two processors are specified to each job. To ...
- 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 ...
- java线程 公平锁 ReentrantLock(boolean fair)
一.公平锁 1.为什么有公平锁 CPU在调度线程的时候是在等待队列里随机挑选一个线程,由于这种随机性所以是无法保证线程先到先得的(synchronized控制的锁就是这种非公平锁).但这样就会产生饥饿 ...
- Fair Scheduler 队列设置经验总结
Fair Scheduler 队列设置经验总结 由于公司的hadoop集群的计算资源不是很充足,需要开启yarn资源队列的资源抢占.在使用过程中,才明白资源抢占的一些特点.在这里总结一下. 只有一个队 ...
- 日常小测:颜色 && Hackerrank Unique_colors
题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...
- Fair Scheduler中的Delay Schedule分析
延迟调度的主要目的是提高数据本地性(data locality),减少数据在网络中的传输.对于那些输入数据不在本地的MapTask,调度器将会延迟调度他们,而把slot分配给那些具备本地性的MapTa ...
- HackerRank "Square Subsequences" !!!
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...
- 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 ...
- HackerRank "TBS Problem" ~ NPC
It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...
随机推荐
- LeetCode 20 -- Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- POJ2653判断直线是否相交
bool judge(node p1,node p2,node p3,node p4){ if(min(p1.x,p2.x)>max(p3.x,p4.x)||min(p1.y,p2.y)& ...
- easyUI参数传递Long型8100131457085857579980953变成8.100131457085857e 24的问题,如下可以解决
function addOptBtn(val, row, index) { var ht = "<a href='${pageContext.request.contextPath}/ ...
- [转]架构蓝图--软件架构 "4+1" 视图模型
架构蓝图--软件架构 "4+1" 视图模型 本文基于多个并发视图的使用情况来说明描述软件密集型系统架构的模型.使用多重视图允许独立地处理各"风险承担人":最终用 ...
- 未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序 解决方法
最近在搞asp.net.今天在做数据库操作的时候,老发生错误,还以为是自己代码有问题,检查了好久都发现错误. 错误提示: 未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程 ...
- 1.2 ASSEMBLY LANGUAGE
People are much happier moving up the ladder,socially or even technically.So our profession has move ...
- 关于struts和Spring 结合到一起之后存在ACtion创建单实例还是多
struts 2的Action是多实例的并非单例,也就是每次请求产生一个Action的对象.原因是:struts 2的Action中包含数据,例如你在页面填写的数据就会包含在Action的成员变量里面 ...
- .gitignore失效问题解决
.gitignore失效背景: 本地Mac上使用Unity新建了一个项目,使用git init将项目初始化为仓库,此时commit.随后,加入.gitignore文件,再次commit.然后提交整个仓 ...
- Default Title
測試的標誌 代表意義 1. 關於某個檔名的『檔案類型』判斷,如 test -e filename 表示存在否 -e 該『檔名』是否存在?(常用) -f 該『檔名』是否存在且為檔案(file)?(常用) ...
- IIS错误:在唯一密钥属性 fileExtension=".url"时,无法添加类型为“mimeMap”的重复集合项
代码可以运行,但没有加载上样式,后来在IIS点击MIME类型时报错了 查看web.config中 <staticContent> <mimeMap fileExtension=&qu ...