标签:
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 = 0;B_i < N;B_i++){ cin >> B[B_i]; } int cnt = 0; for(int i = 0; i < N - 1; i ++) { if(B[i] % 2) { B[i] ++; B[i+1]++; cnt += 2; } } if(B.back() % 2) cout << "NO" << endl; else cout << cnt << endl; return 0; }
标签:
原文地址:http://www.cnblogs.com/tonix/p/5665562.html