hdu 1029 Ignatius and the Princess IV 很简单的一道题。

CRaxsRat v7.6 安装与使用教程(附工具下载) 摘要:本文介绍远程管理工具CRaxsRat v7.6的合法应用与基本操作,强调仅限授权环境使用。该工具支持多客户端管理、TLS加密及文件/进程控制等功能,适用于内网维护与安全测试。安装需Windows 10/11系统及.NET 4.8,步骤包括解压运行、配置监听端口及生成客户端。文中提醒防火墙设置与杀软误报问题,并重申禁止非法用途,建议在虚拟机或隔离环境学习使用。 阅读详情

Ignatius and the Princess IV,链接点这里。

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 26013 Accepted Submission(s): 10993

Problem Description

“OK, you are not too bad, em… But you can never pass the next test.” feng5166 says.

“I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers.” feng5166 says.

“But what is the characteristic of the special integer?” Ignatius asks.

“The integer will appear at least (N+1)/2 times. If you can’t find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha…..” feng5166 says.

Can you find the special integer for Ignatius?

Input

The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file.

Output

For each test case, you have to output only one line which contains the special number you have found.

Sample Input

5
1 3 2 3 3
11
1 1 1 1 1 5 5 5 5 5 5
7
1 1 1 1 1 1 1

Sample Output

3
5
1

Author

Ignatius.L

Recommend

We have carefully selected several similar problems for you: 1074 1171 1203 1114 1069

在做dp专题的时候原本以为这道题是一道Dp,但是看了半天,不知道dp怎么用,倒是觉得是一道挺简单的题。

题意:给你一个整数n,然后是n个整数,求其中的整数中出现次数至少为(n+1)/2 的一个数,输出。

做法:sort一下,然后遍历一遍,找出现个数至少为(n+1)/2的数就ok。


#include<stdio.h>
#include<algorithm>
const int maxn = 1000000;
using namespace std;
int a[maxn];//存数组;
int main()
{
    int t;
    while(~scanf("%d",&t))
    {
        for(int i=0;i<t;i++)
            scanf("%d",&a[i]);//接受数据;

        sort(a,a+t);//排序;

        int flag=a[0],b=1;
        // flag 记录的是当前的数字,初始化为最小的a[0];
        // b 记录当前数组出现的个数;

        for(int i=1;i<t;i++)
        {
            if(a[i]==flag)//判断是否相同;
                b++;   //个数;
            else
            {
                //如果符合情况,跳出;
                if(b>=(t+1)/2)
                    break;

                //否则就重置次数,将当前数字赋值给 flag ;
                b=0;
                flag=a[i];
            }
        }
        printf("%d\n",flag);
    }
    return 0;
}
【零基础学习CAPL】——CAN报文的发送(CRC——ChecSum值) 本章主要介绍带有CRC值的报文发送一般报文可使用CANoe的IG模块直接发送,但带有CRC值的报文就只能编写脚本进行发送,以下详细讲解在配合Panel面板情况下,如何进行带有循环冗余码的报文进行报文的发送。 阅读详情

相关推荐

从零搭建YOLOv2硬件加速器:基于PYNQ-Z2的Vivado HLS与Jupyter Notebook实战

本文详细介绍了如何从零搭建YOLOv2硬件加速器,基于PYNQ-Z2开发板,结合Vivado HLS与Jupyter Notebook实现高效目标检测。通过硬件加速,YOLOv2推理速度提升8倍,功耗降低80%。文章涵盖硬件准备、Vivado HLS工程配置、IP核集成、PYNQ部署及常见问题解决,为开发者提供完整实战指南。

weixin_29188997的博客 1008

ACM HDU 1029Ignatius and the Princess IV

Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 6518    Accepted Submission(s): 2325 Problem Description "OK, yo...

weixin_33957648的博客 146

Unity 实现动态网格地图生成与交互组件

本文详细介绍了在Unity中实现动态网格地图生成与交互组件的完整方案。从基础网格单元实现到高级交互功能,涵盖网格生成器核心逻辑、事件驱动架构、性能优化技巧以及六边形网格等特殊实现。特别适合游戏开发者学习如何构建战棋、模拟经营类游戏的可交互地图系统,提升开发效率与用户体验。

weixin_29015483的博客 1068

HDU 1029 Ignatius and the Princess IV

/* 多元素即在数列中出现次数多于n/2的元素 ————采用这个方法的前提 我们很容易的看出来,在一个序列中如果去掉2个不同的元素, 那么原序列中的多元素,在新的序列中还是多元素, 因此我们只要按照序列依次扫描,先把t赋值给result, 增加个计数器,cnt = 1;然后向右扫描, 如果跟result相同,则cnt++,不同,那么cnt --, 这个真是我们从上面那个结论里得出的,一旦cnt

TT成成的博客 474

《Ventoy 制作系统安装 U 盘的具体步骤》

然后您可以在电脑的磁盘管理中对 U 盘进行快速格式化,选择 FAT32 或 NTFS 文件系统。至此,Ventoy 系统安装 U 盘就制作完成了。您可以在需要安装系统的电脑上,从 U 盘启动,然后选择相应的系统镜像进行安装。安装完成后,将您需要的操作系统镜像文件(如 Windows、Linux 等的 ISO 格式镜像)复制到 U 盘的根目录。在安装程序中,选择您插入的 U 盘设备,确保选择正确,以免误操作。2. 确认选择的 U 盘盘符正确,防止误操作导致其他磁盘数据丢失。点击“安装”按钮,等待安装完成。

jiyiwangluokeji的博客 2666

C/C++关于VScode报错“终端将被任务重用,按任意键关闭”的解决方案

这其实不是一种报错,有这个提示的原因是本地端口是被共享的,所以必须关闭一个进程才能执行另一个,只需要对 tasks.json文件做一些修改即可。 报错时候 此时的tasks.json为: { "version": "2.0.0", "command": "g++", "args": ["-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}.exe"], // 编译命令参数 "problemMatche

Jerry Man的博客 6424

hdu-1029 Ignatius and the Princess IV

hdu-1029 Ignatius and the Princess IV题目描述 Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 28646    Accepted S

oYinGui1 1333

Python爬虫实战:微信小程序内容采集的全面指南

在移动互联网时代,微信小程序已成为企业和个人提供服务的重要渠道。小程序中包含了大量有价值的信息,但微信官方并未提供便捷的数据获取接口。本文将详细介绍如何使用Python爬虫技术采集微信小程序内容,包括最新技术方案、完整代码实现以及应对各种反爬机制的策略。小程序运行在微信封闭环境中,无法直接访问数据通信主要通过HTTPS加密传输内容动态加载,依赖JavaScript渲染微信有严格的反爬机制。

2201_76125261的博客 3116

HDU1029——Ignatius and the Princess IV,HDU1030——Delta-wave,HDU1031——Design T-Shirt

列的矩阵,计算每列的总和,然后找出总和最大的前k列并按照要求的格式输出这些列的索引。这种类型的代码常见于数据分析、统计排序等问题中,尤其是需要根据数据集中的数值进行排序和筛选的场景。函数来估计最近的完全平方数的根,然后加1以确定行号。这是因为每行的左斜线坐标是线性递增的,而且行内第一个点的左斜线坐标为1。计算方法与左斜线坐标类似,但使用了不同的公式,考虑到右斜线坐标的特性。:接下来,代码计算了三个方向上的差异:行、左斜线和右斜线。:最后,将这三个差异相加,并输出结果,这就是两个点在该特殊坐标系下的总距离。

u014114223的博客 1980

通过python+openCV实现对图片中箭头方向的判断

摘要: 针对YOLOv8算法在箭头方向识别效果不佳的问题,提出了一种基于OpenCV的解决方案。该方法通过图像预处理、轮廓分析、几何特征提取(凸包、质心、外接矩形)和方向向量计算,准确判断箭头的上下左右方向。代码示例展示了从图像读取到方向识别的完整流程,并提供了优化建议(如调整二值化阈值、处理多轮廓)。该方案在Windows11+Python3.12+OpenCV环境下验证有效,适用于需要简单几何特征分析的箭头方向检测场景。

AnChenliang_1002的博客 702

AI幻觉缓解的成本效益分析:投入产出比优化

在当今AI技术飞速发展的时代,AI幻觉成为了一个不容忽视的问题。AI幻觉就像是AI在“做梦”,会给出一些不符合实际或者错误的答案。我们这篇文章的目的就是要分析缓解AI幻觉所需要投入的成本和能够获得的效益,看看怎么能让投入和产出的比例达到最优。范围涵盖了常见的AI应用场景,比如智能客服、自动驾驶等领域。接下来,我们会先介绍一些和AI幻觉、成本效益分析相关的术语。然后用一个有趣的故事引出核心概念,解释什么是AI幻觉、成本效益分析等,以及它们之间的关系。

AI 原生应用开发的博客 935

杭电oj HDOJ 1029 Ignatius and the Princess IV

杭电oj HDOJ 1029 Ignatius and the Princess IV 题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1029 Problem Description “OK, you are not too bad, em… But you can never pass the next test.” feng5166 says. ...

qq_39880604的博客 270

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

HDU ACM1029——Ignatius and the Princess IV

Ignatius and the Princess IV Problem Description “OK, you are not too bad, em… But you can never pass the next test.” feng5166 says. “I will tell you an odd number N, and then N integers. There w...

BarisGuo的博客 584

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

HDU - 1029 Ignatius and the Princess IV

OJ地址:https://vjudge.net/problem/HDU-1029 "OK, you are not too bad, em... But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N integers. There will be a s...

分享包括但不限于计算机基础知识、数据结构与算法、Golang技术栈。年与时驰,意与日去,遂成枯落,多不接世,悲守穷庐,将复何及! 1861

HDU 1029 Ignatius and the Princess IV 【桶 | 排序】

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1029 ★这题我用的最机械(愚蠢 )的方法,一个装数字的桶,然而简单的方法也有awa,我用三种方法解决 翻译: 再次感谢 kuangbin的基础DP训练 中的翻译,但不知道这题跟DP啥关系233 思路: 方法一:通过一个桶(数组),若出现的数a,num[a]++;输入完后 循环一次,num[i]大...

HungTeen的博客 253

HDU 1029 Ignatius and the Princess IV (简单DP)

hdu 1029 题目: Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others) Total Submission(s): 42940    Accepted Submission(s): 18774   Problem ...

Kruskal的博客 402

HDU - 1029 Ignatius and the Princess IV (Java - map)

Ignatius and the Princess IV 借此机会,学习了一下java中的map类 import java.util.*; import java.math.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner cin = new Sc...

辞树 200

HDOJ 1029 Ignatius and the Princess IV

题意:求n个数中个数最多的数 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 思路:map维护即可 注意点:无 以下为AC代码: Run ID Submit Time Judge Status Pro.ID Exe.Time Exe.Memory Code Len. Language Author

luminous11的专栏 370

杭电 1029 Ignatius and the Princess IV

http://acm.hdu.edu.cn/showproblem.php?pid=1029 Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others) Total Submission(s): 16754    Accepte

u012766950的专栏 1086

HDU1029:Ignatius and the Princess IV

Problem Description "OK, you are not too bad, em... But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N integers. There will be a special integer amo

ACM!荣耀之路! 2680

HDU-1029 Ignatius and the Princess IV

“OK, you are not too bad, em… But you can never pass the next test.” feng5166 says. “I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell ...

slass-mot-odet 397

hdu 1029 Ignatius and the Princess IV

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 6444    Accepted Submission(s): 2293

sunhui8888的专栏 1212

hdu1029 Ignatius and the Princess IV 水题

Ignatius and the Princess IV Time Limit: 1000MS   Memory Limit: 32767KB   64bit IO Format: %I64d & %I64u Submit Status Description "OK, you are not too bad, em... But y

kyoma的博客 505

HDU - 1029 Ignatius and the Princess IV

DP动态规划水题,小技巧 describe “OK, you are not too bad, em… But you can never pass the next test.” feng5166 says. “I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special

m0_46260869的博客 226
上一篇: poj 1611 The Suspects 并查集
下一篇: nyoj 7 街区最短路径问题 暴力枚举
落幕丶式
博客等级 码龄11年 2粉丝 45原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值