CSU-暑假集训题 B - Parity Alternated Deletions CodeForces - 1144B
作者:互联网
题目链接:http://codeforces.com/problemset/problem/1144/B
思路:
就是将序列分奇数和偶数,如果个数相等或相差一个,就没有剩余,不然就将多的奇数或者偶数从小到大排序,多的个数减去少的个数再减1,输出这些个数的和。
AC代码
#include<iostream> #include<algorithm> using namespace std; const int MAX=1e6+10; long long a[MAX],b[MAX]; int main() { int n; cin>>n; long long num,count1=0,count2=0; long long sum=0; for(int i=0;i<n;i++) { cin>>num; if(num%2==1)a[++count1]=num; else b[++count2]=num; } if(count1==count2) { cout<<0<<endl; return 0; }else if(count1>count2) { sort(a+1,a+count1+1); for(int i=1;i<count1-count2;i++)sum+=a[i]; }else{ sort(b+1,b+count2+1); for(int i=1;i<count2-count1;i++)sum+=b[i]; } cout<<sum<<endl; return 0; }
标签:Deletions,Parity,1144B,int,MAX,long,num,count1,count2 来源: https://www.cnblogs.com/xlbfxx/p/11255393.html