Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
2014-06-09 00:59
375 查看
注意p的边界情况,p为0,或者 p为k
奇数+偶数 = 奇数
奇数+奇数 = 偶数
奇数+偶数 = 奇数
奇数+奇数 = 偶数
#include <iostream> #include <vector> #include <set> #include <algorithm> #include <cmath> using namespace std; int main(){ int n,k,p; long a; cin >> n >> k >> p; vector<long> even, odd; vector<set<long> > parts(k); for(int i = 0 ; i < n ; ++ i){ cin >> a; a%2 ? odd.push_back(a): even.push_back(a); } int even_cnt = p, odd_cnt = k - p; if(odd.size() < odd_cnt || (odd.size() -odd_cnt)%2 ) cout<<"NO"<<endl; else{ for(int i = p; i < k ; ++ i) parts[i].insert(odd[i-p]); if(even.size()+(odd.size()-odd_cnt)/2 < p) cout<<"NO"<<endl; else{ if(even.size() >= p){ for(int i = 0 ; i < p; ++ i) parts[i].insert(even[i]); for(int i = p; i < even.size(); ++ i) parts[p-1 >= 0 ? p-1 : p].insert(even[i]); for(int i = k-p; i < odd.size() ; ++ i ) parts[p-1 >= 0 ? p-1 : p].insert(odd[i]); }else{ for(int i = 0 ; i < even.size(); ++ i) parts[i].insert(even[i]); int j = k-p; for(int i = even.size(); i < p-1; ++ i) parts[i].insert(odd[j++]),parts[i].insert(odd[j++]); while( j < odd.size()) parts[p-1 >= 0 ? p-1 : p].insert(odd[j++]); } cout<<"YES"<<endl; for(int i = 0 ; i < k; ++ i){ set<long> tmp = parts[i]; cout<<tmp.size(); for(set<long>::iterator iter = tmp.begin(); iter!=tmp.end(); ++ iter) cout<<" "<<*iter; cout<<endl; } } } }
相关文章推荐
- Codeforces Round #249 (Div. 2)C Devu and Partitioning of the Array
- Codeforces Round #249 (Div. 2)C Devu and Partitioning of the Array
- codeforces C. Devu and Partitioning of the Array
- codeforces 251 div2 C. Devu and Partitioning of the Array 模拟
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
- Codeforces Round #251 (Div. 2) C Devu and Partitioning of the Array
- Codeforces Round #215 (Div. 1) C. Sereja and the Arrangement of Numbers(欧拉图)
- Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- Codeforces Round #251 (Div. 2) D. Devu and his Brother
- Codeforces Round #251(Div. 2) 439C. Devu and Partitioning of the Array 构造
- Codeforces Round #312 (Div. 2)-B. Amr and The Large Array-暴力
- Codeforces Round#251(Div 2)D Devu and his Brother
- Codeforces Round #250 (Div. 1) D. The Child and Sequence
- Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
- Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...
- Codeforces Round #277.5 (Div. 2)——C贪心—— Given Length and Sum of Digits
- Codeforces Round #179 (Div. 2) C Greg and Array
- Codeforces Round #179 (Div. 1)-A. Greg and Array
- Codeforces Round #253 (Div. 2) E. Artem and Array (思维)
- Codeforces Round #189 (Div. 1) Kalila and Dimna in the Logging Industry 斜率DP