Codeforces Round #152 (Div. 2) A. Cupboards

题目:http://codeforces.com/contest/248/problem/A

n个橱柜 每个橱柜左右两扇门 用0、1纪录关和开的状态,问要使所有左门状态相同,右门状态相同,最少需要对门做几次操作

思路:贪心法 分别统计左右门,输出关闭的状态和打开的状态中的较小值。

#include <iostream>

using namespace std;

int l,r;
int lopen=0,lclose=0,ropen=0,rclose=0;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin >> l>>r;
		if(l==0) lclose++;
		else lopen++;
		if(r==0) rclose++;
		else ropen++;
	}
	l=min(lopen,lclose);
	r=min(ropen,rclose);
	cout<<l+r;
	
	return 0;
}

  

 

posted @ 2013-01-19 22:00  Daniel Qiu  阅读(171)  评论(0编辑  收藏  举报