CodeForces 204B - Little Elephant and Cards

医学图像标注工具教程——从零开始使用3D Slicer进行医学图像手动分割 3D Slicer手动分割软件下载及安装数据导入导入CT序列文件夹导入单张超声基本交互操作窗位和窗宽的调整改变切片及寻找特定点对应的三维切片图像分割功能介绍PaintDrawEraseLevel tracingGrow from seedsFill between slicesThreshold & Margin & HollowSmoothingScissors & IslandsLogical operator分割结果的保存 软件下载及安装 下载地址:官网的4.11.0版本 数据 阅读详情

B. Little Elephant and Cards
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Little Elephant loves to play with color cards.

He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).

Help the Little Elephant to find the minimum number of moves needed to make the set ofn cards funny.

Input

The first line contains a single integer n(1 ≤ n ≤ 105) — the number of the cards. The followingn lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card.

The numbers in the lines are separated by single spaces.

Output

On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.

Sample test(s)
Input
3
4 7
4 7
7 4
Output
0
Input
5
4 7
7 4
2 11
9 7
1 1
Output
2
Note

In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.

In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color7.



=============================

给你一摞牌,两面有数字,问至少要翻转多少张牌可以使正面具有至少一半相同的数字


分别记录下正面和背面每个数出现的次数,算出是否符合条件即可。注意正面和背面可以相等,这时就不算背面,因为只需要保持它正面在上就行了


#include <iostream>
#include <map>
#include <cstdio>

using namespace std;
map<int,int>mp1,mp2;
int a[111111],b[111111];
int n;
int MIN=1e9;

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        if(a[i]==b[i])
        {
            mp1[a[i]]++;
        }
        else
        {
            mp1[a[i]]++;
            mp2[b[i]]++;
        }
    }
    map<int,int>::iterator it;
    for(it=mp1.begin();it!=mp1.end();it++)
    {
        int t=it->first;
        if(mp1[t]>=(n+1)/2)
        {
            printf("0\n");
            return 0;
        }
        if(mp1[t]+mp2[t]<(n+1)/2)
            continue;
        else
        {
            int temp=(n+1)/2-mp1[t];
            MIN=min(temp,MIN);
        }
    }
    for(it=mp2.begin();it!=mp2.end();it++)
    {
        int t=it->first;
        if(mp2[t]>=(n+1)/2)
        {
            MIN=min((n+1)/2,MIN);
            break;
        }
    }
    if(MIN!=1e9) printf("%d\n",MIN);
    else printf("-1\n");
    return 0;
}


Unity游戏开发客户端面经——数据结构(初级) Unity游戏开发客户端面经 之 数据结构篇 阅读详情

相关推荐

Weblogic安装与部署

27.免密登录,在目录Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain\servers\AdminServer和Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain\servers\Server-TA目录下,新建security\boot.properties文件,13.点击新建按钮,填写服务器名称,服务器监听地址,再点击下一步,最后点击完成。

m0_46259466的博客 6635

Codeforce - 204B - Little Elephant and Cards

B. Little Elephant and Cards time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The Little Elephant loves to play with color cards.He has n c

qq_36551426的博客 365

`全网最细!! 入门必看Git教程链接:https://gitee.com/all-about-git`

全网 Git 入门教程 gitee.com。如果显示The requested URL returned error: 403错误,那就表示没有和window本地建立token令牌

qq_37855368的博客 3748

codeforces 204B- Little Elephant and Cards

Description The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Ini

浮躁的人,终究一事无成! 1514

Ubuntu22.04安装ros(一键搞定)

然后发现可以一键安装,话不多说,直接终端输入如下指令。回车之后系统会自动安装ros。

m0_47313541的博客 7413

Allegro如何用自带的功能将线段变成铜皮操作指导

在做PCB设计的时候,有时根据设计需要将线段变成铜皮,可以借助辅助工具来实现这一操作,但是Allegro自身也自带这个功能,如下图。勾选Delete original objects。如何用自带的功能将线段变成铜皮操作指导。勾选Convert to shape,需要把这段走线变成铜皮。

weixin_54787054的博客 2946

Codeforces 204B Little Elephant and Cards

题意: 给你n张卡片,每张卡片都有正反a,b两种颜色,问你至少需要反转多少次才能使正面的一样的颜色超过一半以上。 思路: 统计下每种颜色的个数,只有当一种颜色的个数>=(n+1)/2时我们才考虑它,然后判定下该颜色在正面的个数是否>=(n+1)/2如果大于不需要反转,如果小于则需要反转至少 (n+1)/2-在正面的个数,然后不断维护这个的最小值。 #include #include #i

w446506278的博客 566

【CASS精品教程】013:CASS9.1生成标准图幅案例教程

在CASS中,可以很方便的生成标准图幅,如50*50。本文演示cass中,根据测区范围标准图幅生成过程。

智慧空间实验室 1万+

A - Little Elephant and Cards CodeForces - 205D

The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant

tomjobs的博客 481

Arduino、ESP32驱动SFA40甲醛传感器(气体传感器篇)

SFA40甲醛传感器是一款基于盛思锐电化学原理的专业HCHO检测模块,具备卓越的抗酒精干扰能力(乙醇交叉敏感度<0.3%)、高达±20ppb的检测精度及0~1000ppb的宽量程。该传感器内置SHT4X温湿度传感器进行自动补偿,确保数据的长期稳定性;其小尺寸、低功耗的特性,可快速集成至智能家居、空气净化器、物联网环境监测等系统中,实现对甲醛浓度的精准、可靠监测。

不脱发的程序猿 302

【单智能体】AI 数据分析智能体案例讲解(附完整源码)

本案例将引导您构建一个基于 AI 的数据分析智能体,让用户能够通过自然语言查询来分析 CSV 和 Excel 文件中的数据,无需掌握 SQL 知识。该智能体使用 Agno Agent 框架集成 OpenAI GPT-4o 模型,并利用 DuckDB 提供高效的数据处理能力。

rengang66的博客 239

A. Little Elephant and Chess

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The Little Elephant loves chess very much. One day the Little

无知的我 7万+

如何在 SAP BTP 上使用 Integration Suite 消费 S/4HANA Cloud API

SAP Integration Suite是一个集成平台即服务(iPaaS),允许开发人员顺利地将内部部署和基于云的应用程序和流程与SAP管理的工具和预构建内容进行集成。登录 SAP Business Technology Platform Cockpit,进入 integration suite:再点击 API management 进入 API Portal:或者直接从收藏夹里打开链接:https://304a49cetrial.integrationsuitetrial-apiportal.cfapp

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1698

D - Little Elephant and Chess (模拟)

The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered boa...

云乐 508

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Codeforces Round #129 (Div. 1) B. Little Elephant and Cards

B. Little Elephant and Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The Little Elephant loves to p

喵呜的Blog 1997

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

CF:259A. Little Elephant and Chess

经分析,只要有一行有相邻的两个字符相同,就不能转换成题目所要求的。 #include #include using namespace std; int main(){ string c[8]; while(cin>>c[0]){ for(int i=1;i<8;++i) cin>>c[i]; int t=1;

Ac_freedom 1117

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

CodeForces 165C - Another Problem on Strings

C. Another Problem on Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A string is binary, if it con

coco430的专栏 1270

CodeForces 149B - Martian Clock

B. Martian Clock time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Having stayed home alone, Petya decided to

coco430的专栏 1077

CodeForces 165B - Burning Midnight Oil(二分)

B. Burning Midnight Oil time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day a highly important task was

coco430的专栏 1074

CodeForces 160B - Unlucky Ticket

B. Unlucky Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Each of you probably has your personal ex

coco430的专栏 947

CodeForces 141B - Hopscotch

B. Hopscotch time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output So nearly half of the winter is over and Maria

coco430的专栏 929

CodeForces 149C - Division into Teams(贪心)

C. Division into Teams time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petya loves football very much, espe

coco430的专栏 917

CodeForces 148C - Terse princess

C. Terse princess time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output «Next please», — the princess called and

coco430的专栏 765

CodeForces 148B - Escape

B. Escape time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The princess is going to escape the dragon's cave

coco430的专栏 749

CodeForces 155B - Combination(贪心)

B. Combination time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ilya plays a card game by the following rule

coco430的专栏 747

CodeForces 214E - Relay Race(二取方格数)

E. Relay Race time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Furik and Rubik take part in a relay race. The race wil

coco430的专栏 742
上一篇: 杂记
下一篇: CodeForces 214E - Relay Race(二取方格数)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值