CF248A.Cupboards
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
一个雾蒙蒙的斯德哥尔摩清晨,卡尔松决定去他朋友利勒布罗·斯万滕松家吃点果酱当零食。幸运的是,他朋友家里此时空无一人。卡尔松再也不想挨饿了,于是决定在房子里找些食物。
卡尔松的目光立刻落在厨房里并排摆放的 $ n $ 个木制橱柜上。他马上意识到,这些橱柜里藏着果酱储备。卡尔松便贪婪地在厨房中飞来飞去,不停地开关橱柜门,拿走并吃光所有他能找到的果酱罐头。
现在,所有的果酱罐头都已空空如也,卡尔松也吃饱了,而且他不想留下自己到访过的痕迹,以免让朋友失望。每个橱柜都有两扇门:左门和右门。卡尔松记得,当他冲进厨房时,所有橱柜的左门都处于相同的状态(全开或全关),同样,所有橱柜的右门也都处于相同的状态(全开或全关)。因此,他希望在家人回来之前,也让所有橱柜的门恢复成这种状态:即所有左门状态一致,所有右门状态一致。卡尔松不记得当初所有左门具体是开着还是关着,也无法回忆起所有右门的具体状态。因此,他并不在意最终所有左门究竟统一为开还是关,也不在意所有右门最终统一为开还是关;他只关心——所有左门状态必须相同,所有右门状态也必须相同。例如,可以是所有左门关闭、所有右门打开。
卡尔松开关一扇橱柜门需要花费一秒时间。他深知家人很快就会回来,因此他想知道:使所有橱柜门满足上述要求所需的最短时间(以秒为单位)$ t $ 是多少?
你的任务是编写一个程序,计算出所需的最短时间 $ t $。
输入格式
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 l__i and r__i (0 ≤ l__i, r__i ≤ 1). Number l__i equals one, if the left door of the i-th cupboard is opened, otherwise number l__i equals zero. Similarly, number r__i equals one, if the right door of the i-th cupboard is opened, otherwise number r__i equals zero.
The numbers in the lines are separated by single spaces.
第一行输入包含一个整数 n —— 厨房中橱柜的数量(2≤n≤104)。接下来是 n 行,每行包含两个整数 li 和 ri(0≤li,ri≤1)。若第 i 个橱柜的左门处于打开状态,则 li=1,否则 li=0。类似地,若第 i 个橱柜的右门处于打开状态,则 ri=1,否则 ri=0。
每行中的数字以单个空格分隔。
输出格式
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.
在唯一的一行输出中,打印一个整数 t —— 卡尔松将所有橱柜的门调整到他所需位置所需的最少秒数。
输入输出样例
输入#1
5 0 1 1 0 0 1 1 1 0 1
输出#1
3
输入解题思路,AI测评打分。不知道怎么写?