该卡最低翻转 [英] Minimum Flipping of the cards

查看:116
本文介绍了该卡最低翻转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有哪些号码都写在正面以及back.Now n播放卡在一个举动我可以翻转的任何卡,使其底部现在成为顶部。

I have N playing cards on which numbers are written on front as well as back.Now In one move I can flip any card so that its bottom now becomes the top.

鉴于卡我需要找到的动作,可以使至少一半的卡显示在他们最相同数量的最小数目在上面的数字和底部。

Given the numbers on top and bottom of cards I need to find minimum number of moves that can make at least half of the cards show same number on their top.

如果这是不可能这样做的,然后还告诉它是不可能的。

If it is not possible to do so then also tell that it is not possible.

例:假设我们有3张牌并重新presented为(底部数之上,数)

Example : Say we have 3 cards and represented as (number on top,number on bottom)

卡1:(3,10)

卡2:(10,3)

卡3:(5,4)

现在,这里minmum举动仅仅是1,因为我们可翻转的第一张牌等上面,这个数字变为10。由于两人的三张牌在其顶(10)相同的号码,我们不需要改变什么别的,所以答案为1。

Now ,here minmum moves is just 1 as we can flip the first card so that number on the top becomes 10. Since two of the three cards have same number on their top (10), we do not need to change anything else, so the answer is 1.

推荐答案

下面的说明是不是从你的问题完全明确的:

The following point is not completely clear from your question:

  • 在我假设你有完整的信息,也就是说,你知道的从一开始就的东西在上面每张卡片的底部;
  • I'm assuming that you have the complete information, ie that you know from the beginning what is on top an bottom of each card;

我会去为以下内容:

  • 让N =的卡的数量;
  • 对于每个编号出现在一张卡片上,数数<$ ​​C $ C> M(1)的卡在那里出现(顶部或底部);
  • 如果没有 M(1)大于 N / 2 然后失败
  • 对于每个编号出现在一个线,数数<$ ​​C $ C>顶(我),如果出现在哪里卡在上面;​​
  • 计算 C 的数量,其中 M(C) - 高层(C)最小;
  • 翻转 M(C) - 高层(C),使得 C 是底部,但不是在上面。
  • let N = number of cards;
  • for each number i appearing on a card, count the number m(i) of cards where it appear (top or bottom);
  • if no m(i) is greater than N/2 then fail
  • for each number i appearing on a cord, count the number top(i) of cards where if appear on top;
  • compute c the number where m(c) - top(c) is minimum;
  • flip m(c) - top(c) such that c is on bottom but not on top.

这篇关于该卡最低翻转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆