# [笔试]地域划分

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int>iVec;
int Num;
cin>>Num;
for(int i = 0; i < Num;i++)
{
int iEveryNum;
cin>>iEveryNum;
iVec.push_back(iEveryNum);
}
vector<int>iVec1;
for(int i = 0; i <= iVec.size();i++)
{
int icount0 = 0;
int icount1 = 0;
if(i == 0)
{
icount1 = count(iVec.begin(),iVec.end(),1);
icount0 = count(iVec.begin(),iVec.end(),0);
iVec1.push_back((icount1<icount0)?icount1:icount0);
}
else if(i == iVec.size())
{
icount1 = count(iVec.begin(),iVec.end(),1);
icount0 = count(iVec.begin(),iVec.end(),0);
iVec1.push_back((icount1<icount0)?icount1:icount0);
}
else
{
int totalNum1,totalNum2;
icount1 = count(iVec.begin(),iVec.begin()+i,1);
icount0 = count(iVec.begin()+i,iVec.end(),0);
totalNum1 = icount1+icount0;
icount0 = count(iVec.begin(),iVec.begin()+i,0);
icount1 = count(iVec.begin()+i,iVec.end(),1);
totalNum2 = icount1+icount0;
iVec1.push_back((totalNum1 < totalNum2)?totalNum1:totalNum2);
}
}
vector<int>iVec3;
iVec3 = iVec1;
sort(iVec3.begin(),iVec3.end());
vector<int>::iterator it = iVec1.begin();
it = find(iVec1.begin(),iVec1.end(),iVec3[0]);
cout<<it-iVec1.begin()<<" "<<it-iVec1.begin()+1<<endl;
system("pause");
return 0;
}



• 本文已收录于以下专栏：

举报原因： 您举报文章：[笔试]地域划分 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)