# [笔试]地域划分

125人阅读 评论(0)

#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;
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：26919次
• 积分：1132
• 等级：
• 排名：千里之外
• 原创：86篇
• 转载：2篇
• 译文：0篇
• 评论：9条
评论排行
最新评论