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 ;
}
上一篇:零碎记录Hadoop平台各组件使用


下一篇:【Discuz】-QQ互联登陆提示错误信息:Unknown column 'conuintoken' in 'field list'