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

手把手教你学Simulink--电机电磁兼容与可靠性​场景示例:基于Simulink的电机轴电压与轴电流抑制仿真 本文带你完成了电机轴电压与轴电流抑制的Simulink仿真,实现了:✅ 揭示了共模电压 → 寄生电容 → 轴电压 → 轴承电蚀的完整链路✅ 搭建了含寄生参数的高频电机等效模型共模电压最小化PWM(源头抑制)dv/dt滤波器(路径阻断)轴接地(终端泄放) ✅ 通过仿真验证了轴电压从68 V降至<3 V的显著效果 ✅ 为高可靠性电机系统提供低成本、高效益的轴承保护方案。 阅读详情

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;
}
YOLOv11训练:Roboflow免费数据集获取与格式转换超详细教程 公共数据集库:包含超过20,000个开源数据集数据标注工具:支持在线标注和团队协作数据预处理:自动增强、扩充和格式化版本控制:像管理代码一样管理数据集版本多格式导出:支持所有主流目标检测格式import cv2# 加载图像# 加载标注# 数据增强# 调整尺寸# 调整标注坐标# 转换为Tensor# 实现保持长宽比的resize逻辑pass# 坐标转换逻辑pass# 数据增强实现pass数据集选择优先选择Roboflow上标注质量高的官方数据集。 阅读详情

相关推荐

智慧工地算法视频分析服务器区域入侵检测AI视频分析技术在煤矿的实战应用

通过实时分析和处理井下视频资料,智慧矿山算法视频分析服务器不仅能够及时发现并预警人员违规行为和设备异常状况,还能够通过智能分析预防潜在的安全风险,从而显著提高煤矿的安全管理水平和生产效率。

EasyDarwin开源社区技术博客 560

HDU 1029 Ignatius and the Princess IV

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

TT成成的博客 474

ASPP - 空洞空间金字塔池化

文章目录1 空洞卷积1.1 空洞卷积的理解1.1.1 一维1.1.2 二维1.2 空洞卷积的优劣2. ASPP3. 代码 1 空洞卷积 1.1 空洞卷积的理解 1.1.1 一维 (a) 正常卷积:输入特征 Input feature,kernel = 3,stride = 1,pad = 1,输出特征 Output feature。 (b) 空洞卷积:与图 (a) 不同之处在于 pad = 2,同时引入一个 rate = 2(表示卷积核中参数间间隔的超参)。   还可通过下图进一步理解普通卷积与空洞卷

晓野豬 2万+

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中的粒子系统Particle System (三)

上一篇我们详细讲解了有关主模块的全部内容,已经对粒子系统的基本运作有了足够的了解,本篇就来讲一下被粒子系统默认启用的Emission、Shape、Renderer模块又在粒子系统中扮演着怎么样的作用吧。

梦小天幼的博客 1万+

【学长笔记】点亮 STM32F411CEU6 板载 LED —— 入门级教程

本文提供了STM32F411CEU6开发板(Black Pill)点亮LED的完整教程。详细介绍了硬件信息(板载LED连接PC13,低电平有效)、CubeMX配置步骤(GPIO输出模式)、Keil5工程设置及完整代码实现(包含GPIO初始化和系统时钟配置)。教程还涵盖ST-Link下载器连接方法、程序下载步骤(需配合BOOT0按键操作)以及验证程序运行的方法。该教程特别适合STM32初学者,通过简单的LED闪烁示例快速入门STM32开发。

apple_53308981的博客 1320

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

Claude Code 错误解决方案 使用策略拒绝 Usage Policy refusal

摘要:本文分析了Claude Code API请求被拒绝的问题,当违反Usage Policy时会显示错误提示。根因包括请求内容违规、模型敏感度差异或历史消息影响。解决方案包括修改请求措辞、切换至Sonnet 4.5模型或开启新会话。文章详细追踪了错误链路,提供了核心代码分析,并给出验证方法和最佳实践建议,帮助用户避免触发API拒绝机制。

多媒体编程、网络编程、系统编程、网络安全编程、驱动编程 972

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

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

u014114223的博客 1980

IEC 61850标准协议解读 3.MMS服务

摘要:本文系统介绍了MMS(制造报文规范)的基础知识及其在IEC61850中的应用。首先解析MMS的核心定义、通信流程(带确认/不带确认服务)、虚拟制造设备(VMD)概念及核心对象(域/有名变量等)。重点阐述IEC61850与MMS的映射关系,包括对象分层映射、服务转换规则及数据类型对应。深入分析ASN.1编解码机制,说明MMS PDU的分层结构与解码流程。最后通过典型报文案例(报告服务、控制服务、文件传输等)和通信初始化流程,展示MMS在智能变电站中的实际应用。全文揭示了MMS作为抽象应用层协议如何通过标

张二狗的博客 724

STM32实战开发(76):STM32开发无线传感器网络(WSN)完整实现

本文介绍了如何基于STM32开发无线传感器网络,包括硬件选择、通信协议、系统设计和编程实现。通过STM32的强大性能和低功耗特性,我们能够构建高效、可靠的无线传感器网络。无论是Zigbee、LoRa、Wi-Fi还是BLE协议,STM32都能够与多种通信模块进行兼容,满足不同应用的需求。希望这篇文章能帮助您了解无线传感器网络的构建流程,并为您的项目提供有价值的参考。

2201_76125393的博客 1058

杭电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

5ZCM6ZGrVDllSFLkv6Hmga/ljJbnrqHnkIbns7vnu58= GetFlowDropDown SQL注入

5ZCM6ZGrVDllSFLkv6Hmga/ljJbnrqHnkIbns7vnu58=、eHR/OA一体化智慧云平台、智慧一卡通云平台、行业软件开发与定制、智慧企业管理信息化咨询与项目服务为核心业务的顾问式管理咨询和软件个性定制开发的高科技股份集团公司。同鑫T9eHR信息华管理系统存在SQL注入漏洞,攻击者可通过该漏洞上传shell。关闭互联网暴露面或接口设置访问权限。利用sqlmap进行shell。

iSee857的博客 700

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

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

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

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

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

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

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、付费专栏及课程。

余额充值