A. Cupboards

编程知识 更新时间:2023-05-02 19:11:32

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.

Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.

And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.

Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.

Your task is to write a program that will determine the required number of seconds t.

Input

The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.

The numbers in the lines are separated by single spaces.

Output

In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.

Sample test(s) input
5
0 1
1 0
0 1
1 1
0 1
output
3


解题说明:此题就统计两列中0,1的个数即可


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;



int main()
{
	int n,i;
	int sum1,sum2;
	int count;
	int a,b;
	sum1=0;
	sum2=0;
	count=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&a,&b);
		if(a==1)
		{
			sum1++;
		}
		if(b==1)
		{
			sum2++;
		}
	}
	if(sum1*2>n)
	{
		count+=n-sum1;
	}
	else 
	{
		count+=sum1;
	}
	if(sum2*2>n)
	{
		count+=n-sum2;
	}
	else
	{
		count+=sum2;
	}
	printf("%d\n",count);
	
	return 0;
}


更多推荐

A. Cupboards

本文发布于:2023-04-28 05:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/c004f94964f9b68c9376e521bdfe4d9a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Cupboards

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 107776文章数
  • 27244阅读数
  • 0评论数