codeforces 439C Devu and Partitioning of the Array(烦死人的多情况的模拟)
//这是一道有n多情况的烦死人的让我错了n遍的模拟题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> using namespace std; int a[100010],n,k,p; int vis[100010]; int ji=0,ou=0; int main() { memset(vis,0,sizeof(vis)); cin >> n >> k >> p; for(int i=0;i<n;i++) { cin >> a[i]; if(a[i]%2==1) ji++; else ou++; } if((ji-(k-p))%2==1||ji<k-p||((ji-(k-p))/2+ou<p)) printf("NO\n"); else { printf("YES\n"); int odd=0,even=0,al=0; if(p!=0) { for(int i=0;i<n;i++) { if(a[i]%2) { if(odd<k-p) { printf("1 %d\n",a[i]); odd++; vis[i]=1; al++; } else break; } } for(int i=0;i<n;i++) { if(a[i]%2==0) { if(even<p-1) { printf("1 %d\n",a[i]); even++; vis[i]=1; al++; } else break; } } int flag=1; for(int i=0;i<n;i++) { if(even<p-1) { if(vis[i]==0&&a[i]%2==1&&flag==1) printf("2 %d",a[i]),flag=0,vis[i]=1,al++; else if(vis[i]==0&&a[i]%2==1&&flag==0) printf(" %d\n",a[i]),flag=1,vis[i]=1,even++,al++; } else break; } if(n-al>0) { cout << n-al; for(int i=0;i<n;i++) { if(vis[i]==0) printf(" %d",a[i]); } } } else { for(int i=0;i<n;i++) { if(a[i]%2) { if(odd<k-p-1) { printf("1 %d\n",a[i]); odd++; vis[i]=1; al++; } else break; } } if(n-al>0) { cout << n-al; for(int i=0;i<n;i++) { if(vis[i]==0) printf(" %d",a[i]); } } } puts(""); } return 0; }
一道又一道,好高兴!