【B - Ignatius and the Princess IV】

不同比例尺地质数据共享 包含20w、25w、100w、250w比例尺地质数据共享。 阅读详情

思路:

  • 暴力:存储所有数字,sort,其中位数一定是答案。
  • 动态规划:取消数组,维护两个变量 cur 和 num。新读入的数如果是 cur,num++;如不是 cur,则 num- -。因为目标出现次数超过一半,所以当目标数全都在一起时,最后也有 num>0;在分散最开的情况下,两两抵消,最后三个数中出现两次的即为答案。故做法成立。

代码:

  • 暴力:187ms 2544kB
​//187ms		2544kB


#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 1e6 + 5;

int N;
int num[maxn];

int main(){
	while(~scanf("%d" , &N)){
		for(int i=0;i<N;i++)
			scanf("%d" , num + i);
		sort(num , num+N);
		printf("%d\n" , num[(N+1)/2]);
	}
	return 0;
}​
  • 动态规划:156ms 1368kB
​//156ms		1368kB


#include <iostream>

using namespace std;

int main(){
	int N;
	int cur;//当前使用的数字 
	int num;//cur出现次数  
	while(~scanf("%d" , &N)){
		num = 0;
		int t;
		while(N--){
			scanf("%d" , &t);
			if(!num){
				cur = t;
				num++;
			}
			else{
				if(cur == t)
					num++;
				else
					num--;
			}
		}
		printf("%d\n" , cur);
	}
	return 0;
}​
【Bug已解决】Claude Desktop Cowork 报错 Workspace unavailable 解决方案 方案适用场景推荐指数确认虚拟机镜像下载完整性排查的第一步,最基础的前提检查⭐⭐⭐⭐⭐确认虚拟机平台功能已启用Windows 系统功能层面的必要条件⭐⭐⭐⭐⭐重启 CoworkVMService快速尝试恢复服务正常状态⭐⭐⭐⭐完全重启客户端排除临时性状态错乱⭐⭐⭐⭐降级使用文件工具临时替代方案,不阻塞当前工作⭐⭐⭐报错的本质是Cowork 功能依赖的虚拟机管理服务,在 Windows 应用包隔离机制下未能正确定位虚拟机文件的实际存放路径。 阅读详情

相关推荐

STM32MP157+AD7606BSTZ四通道IEPE传感器采集方案实战(附完整电路图)

本文详细介绍了基于STM32MP157和AD7606BSTZ的四通道IEPE传感器采集方案,涵盖硬件电路设计、软件驱动开发及系统性能优化。通过精确的恒流源设计和同步采样技术,实现高精度振动信号采集,适用于工业振动监测等应用场景。

weixin_42713608的博客 702

B - Ignatius and the Princess IV

B - Ignatius and the Princess IV 题目入口:B - Ignatius and the Princess IV 杭电入口:Ignatius and the Princess IV 解题思路 题目:给一列数,找出出现(n+1)/2次的数字 第二个代码为直接模拟 过掉不说 第一个代码的巧妙之处 设一个标志 通过输入更新标志 如果输入的数和前边的数不同就–cnt 否则++c...

恒治学 392

将外部电磁近场数据导入 ANSYS HFSS

本博客介绍了如何将电磁近场数据导入 ANSYS HFSS。用户可能需要导入字段,无论是通过分析计算、测量、由其他工具生成还是从提供商处接收的字段,并将其用作实际激励来执行不同类型的分析。以下是导入过程的简要概述,视频链接中提供了完整的演示。为了定义简单基元近场源,HFSS 使用两种外部数据文件。首先,实际位置/字段数据以 .nfd 格式存储。其次,Ansys Near field Descriptor 文件(.and 文件)存储 .nfd 数据的一般几何信息和路径。

jkh920184196的博客 2324

B - Ignatius and the Princess IV 【思维】

hdu1029 Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others) Total Submission(s): 33825    Accepted Submission(s): 14660 Probl

hubayi31072的博客 255

在Matlab中开发AutoSAR模型的流程(自下而上)

前面介绍了AutoSAR软件组件开发的两种方式,其中自下向上的方式,是从模型出发,流程如下。

小胡同学的工程师学习之路 5366

零基础学写《扫雷》游戏(Qt扫雷源码)

扫雷游戏是在windows系统中自带的游戏,他的游戏玩法其实很简单,20世纪初期电脑上没有啥游戏可以玩,所以扫雷游戏也算是当时是最常火爆的一个电脑游戏。以下文章详细介绍扫雷游戏的实现。实现语言为C++。

啊渊的专栏 1万+

B - Ignatius and the Princess IV【DP】

“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 m

Irish_Moonshine的博客 371

Opencascade 保存点云为 .stp 和 .step 格式

总结一下,OpenCascade提供了强大的功能和工具,使我们能够方便地将点云数据保存为 .stp 和 .step 格式。通过使用类似于上述示例代码的方法,你可以使用OpenCascade库将点云数据保存为.STP和.STEP格式。总结一下,使用OpenCascade库,你可以方便地将点云数据保存为.STP和.STEP格式。通过使用类似于上述示例代码的方法,你可以将点云数据转换为OpenCascade的几何模型,并将其保存为所需的文件格式。请注意,上述代码仅涵盖了将点云数据保存为.STP格式的基本步骤。

CwzCode的博客 1157

B - Ignatius and the Princess IV DP

#include<iostream> #include<vector> using namespace std; int cnt[999999]; int main() { int time,n,limit; vector<int> been; while(cin>>time) { ...

aocan6909的博客 136

华为od 面试八股文_C++_02_含答案

华为od 面试八股文_C++_02_含答案

MISAYAONE的博客 3121

Python操作WPS文档

在Python中,我们可以使用第三方库来操作WPS文档,实现自动化的文档处理。本文将介绍如何使用Python来打开、读取、修改和保存WPS文档的内容。库,我们可以打开、读取、修改和保存WPS文档的内容。你可以根据自己的需求进一步扩展和优化这些代码,实现更复杂的文档处理功能。安装完成后,我们就可以开始使用它来操作WPS文档了。方法将修改后的文档保存到指定的路径。方法将修改后的文档保存到指定的路径。在上面的代码中,我们通过修改段落的。属性,可以改变段落的文本内容。完成对文档的修改后,我们可以使用。

2301_79366177的博客 5615

B - Ignatius and the Princess IV——POJ

B - 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 you can neve

你那么爱笑,家里人知道吗? 1827

无人机:DJI Matrice 600 Pro_(8).DJI_Matrice_600_Pro_负载能力

在一些高级应用场景中,可能需要自定义开发负载设备。

zhubeibei168的博客 1341

B - 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, ...

chen_zan_yu_的博客 407

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

hpu暑假训练 B - Ignatius and the Princess IV 【sort】

B - 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 sp

tian_he_he的博客 323

数学建模模型总结

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

第二题:B - Ignatius and the Princess IV

题意:给n个数字,n为奇数,求一个数字x,x的个数大于等于(n+1)/2 解法一:map容器 思路:n的范围为1000000,但是元素x值不明,所以我们用map的第一个元素去存x,第二个元素存x的次数 代码: #include<bits/stdc++.h> #include<map> using namespace std; #define maxn 100000...

柯微 149

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

B - Ignatius and the Princess IV 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 special integer among them, you have to tel...

mystical_curve的博客 282

hdu 1029 B - Ignatius and the Princess IV 思维

题目链接 大体题意就是让你输出奇数个数的数列中出现次数大于 n/2的那个        我记得类似的题目啊哈的最后出现过,我们肯定首先想到的就是排序然后输出中间那个,但是这样的复杂度是快排为nlogn,那么我们有没有线性的方法呢? 有一个比较好的方法就是 我们可以利用该数出现n/2 的性质,那么我们每次删除数组中的两个数,一直删到最后留下的就一定是那个出现次数超过n/2的那个 #inclu

Marcus-Bao的个人主页 549

B - Ignatius and the Princess IV (DP+模拟)

B - 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 you can never pass the next te

qwesde 812

B - Ignatius and the Princess IV (水题)

“好吧,你不是太糟糕,他们......但你永远无法通过下一次测试。” feng5166说。  “我会告诉你一个奇数N,然后N个整数。它们之间会有一个特殊的整数,你告诉我在告诉你所有整数之后哪个整数是特殊的。” feng5166说。  “但特殊整数的特征是什么?” 伊格内修斯问道。  “整数至少会出现(N + 1)/ 2次。如果你找不到合适的整数,我会杀死公主,你也将成为我的晚餐。哈哈哈哈........

立志变成java巨头 403
上一篇: 【A - Max Sum Plus Plus】
下一篇: 【C - Monkey and Banana】
Masker_43
博客等级 码龄8年 5粉丝 143原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值