1048 Find Coins (25 point(s))

2025 居民消费结构数据集(21列,15000条记录)XLSX 详情介绍:该数据集为 2025 年 12 个月、1250 户家庭的平衡面板消费数据,15000 行 ×21 列零缺失,覆盖 31 省、城乡均衡,含八大类消费支出和恩格尔系数(均值 0.293,属富裕区间),家庭月收入均值 8473 元、月支出 6487 元,附完整字段说明 sheet,数据干净规整,非常适合做消费结构分析、面板回归、城乡 / 区域差异对比和收入等级分类预测,但为合成数据、仅 1 年时间跨度,不适合做真实政策研究或长期趋势分析。 立即下载

1048 Find Coins (25 point(s))

Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special requirement of the payment: for each bill, she could only use exactly two coins to pay the exact amount. Since she has as many as 10​5​​ coins with her, she definitely needs your help. You are supposed to tell her, for any given amount of money, whether or not she can find two coins to pay for it.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive numbers: N (≤10​5​​, the total number of coins) and M (≤10​3​​, the amount of money Eva has to pay). The second line contains N face values of the coins, which are all positive numbers no more than 500. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the two face values V​1​​ and V​2​​ (separated by a space) such that V​1​​+V​2​​=Mand V​1​​≤V​2​​. If such a solution is not unique, output the one with the smallest V​1​​. If there is no solution, output No Solution instead.

Sample Input 1:

8 15
1 2 8 7 2 4 11 15

Sample Output 1:

4 11

Sample Input 2:

7 14
1 8 7 2 4 11 15

Sample Output 2:

No Solution

思想:Hash表

题意:在一个数组中寻找恰好两个数(不超过500),让其组成恰好等于M(不超过1000)。并由小到大输出这两个数,如果多组解,则输出第一个数小的解。

基本思路: 构建哈希表,记录每一个数的个数cnt[i]。由小到大遍历哈希表,如果cnt[i]>=1&&cnt[M-i]>=1,则得到结果。注意判断两个相同的硬币组成M的情况。

踩坑:case#3段错误(23分)

由于数组大小刚好是500,在判断的时候M-i可能大于500,因此出现段错误。解决方案:1. 数组长度改为1001;2. 判断M-i<=500。

#include<iostream>
using namespace std;
const int MAX = 507;
int cnt[MAX]={0};
int main(void){
	int N,M,a;cin>>N>>M;
	for(int i=0;i<N;i++){
		cin>>a;
		cnt[a]++;
	}
	bool flag=false;
	for(int i=1;i<=M;i++){
		if(i+i==M){
			if(cnt[i]>=2){
				cout<<i<<" "<<i<<endl;
				flag=true;
				break;
			}
		}
		else{
			if(cnt[i]>=1&&M-i<=500&&cnt[M-i]>=1){
				cout<<i<<" "<<M-i<<endl;
				flag=true;
				break;
			}
		}
	}
	if(!flag) cout<<"No Solution"<<endl;
	return 0;
}

 

量化爬虫实战:手把手教你搞定同花顺问财的hexin-v参数(附JS逆向思路与Cookie Hook技巧) 本文详细解析了如何通过JS逆向技术获取同花顺问财平台的`hexin-v`参数,包括Cookie Hook技巧和完整解决方案架构。从环境搭建到参数定位,再到生成逻辑逆向,手把手教你突破数据获取限制,为量化交易提供可靠数据支持。 阅读详情

相关推荐

Token验证绕过 靶场实战

实验介绍 1.漏洞简介 在Web领域基于Token的身份验证随处可见。在大多数使用Web API的互联网公司中,tokens 是多用户下处理认证的最佳方式。 具有以下几点特性: 1)无状态、可扩展 2)支持移动设备 3)跨程序调用 4)安全 2.原理基于Token的验证原理 基于Token的身份验证是无状态的,我们不将用户信息存在服务器或Session中。 NoSession意味着你的程序可以根据需要去增减机器,而不用去担心用户是...

weixin_54771278的博客 2251

PAT-1048 Find Coins

1048 Find Coins(25 分) Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coin...

Eric的博客 318

ESP32S3与ILI9341 LCD屏LVGL移植实战:从零构建嵌入式GUI界面

本文详细介绍了如何在ESP32S3平台上移植LVGL图形库并驱动ILI9341 LCD屏幕,从硬件选型、开发环境配置到显示驱动实现和内存优化。通过实战案例讲解移植过程中的关键步骤和常见问题解决方案,帮助开发者快速构建嵌入式GUI界面。

h9j8k7l6m5n的博客 1097

1048 Find Coins

#include&lt;bits/stdc++.h&gt; using namespace std; int main() { //freopen("in.txt","r",stdin); int n,m;cin&gt;&gt;n&gt;&gt;m; vector&lt;int&gt; ppp; ppp.resize(n); for(int i=0;i&lt;n;i++){ cin

csg3140100993的博客 245

Perplexity AI 高效使用培训手册

Perplexity AI 是一款革命性的 AI 搜索引擎,提供免费版和专业版两种选择。免费版支持基础搜索、每日3次Pro搜索、3个文件上传和初步深度研究功能;Pro版则解锁无限次Pro搜索、无限制文件上传、AI图像生成等高级功能,适合专业用户深度研究。该工具能整合网络信息、分析本地文档、生成创意内容,并提供知识库管理功能,显著提升信息检索和内容创作效率。用户可根据需求选择合适版本,免费版已能满足日常使用,而Pro版则更适合专业场景。

conquer_qgw的博客 1207

手把手教你用高频注入法辨识永磁同步电机电感参数(附MATLAB仿真)

本文详细介绍了高频注入法在永磁同步电机电感参数辨识中的工程实践与MATLAB仿真指南。通过高频信号注入法,无需拆解电机即可在线精确测量Ld和Lq参数,适用于电动汽车驱动和工业伺服等高精度控制场景。文章包含信号设计、硬件实现、解调算法及完整MATLAB仿真模型构建,帮助工程师快速掌握这一关键技术。

orange的博客 292

【PAT甲级】1048 Find Coins(散列/二分)

Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...

Y_CanFly的小小博客 325

【清华大学软院】15-19年推免试题历年整理

整理的题目为清软预推免机试(外校)硕士机考题目。 年代 题目1 题目2 题目3 2019 质因数分解 二叉搜索树 区间DP(折叠字符串) 2018 日期转换 高精度模拟 区间DP(戳气球) 2017 进制素数 被遗漏的数字 DP(收集苹果) 2016 大数运算 DP DFS 2015 进制素数: http://acm.hdu.edu.cn/showproblem.php?pid=1230 2017年题目(这个是找的最准确的题目): 1题见【链接】 2题见【链接】

云端筑梦师 2255

PAT 甲级 1048 Find Coins (c语言实现)

来看看题目 这个题我的理解是 将这n个数先排序 再对排好序的n个数进行循环算出两两之和 若满足两数v1+v2=m&amp;&amp;v1&lt;v2则输出 且只输出满足这个条件的第一组数据(这个用flag控制) 否则输出No solution 但是这道题并没有AC 出现了段错误 #include &lt;stdio.h&gt; #include &lt;stdlib.h&...

zouzou_的博客 327

pynq-z2 HLS开发

定制Overlay一.用HLS生成一个定制IP功啊啊是合理的创建标题,有助于目录的生成如何改变是式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 一.用HLS生成一个定制IP ...

qq_38769280的博客 4156

实战全解|大疆司空2二次开发:从接口开发到第三方业务系统深度融合

大疆司空2二次开发是实现行业无人机定制化应用的关键,通过OpenAPI后端对接+前端组件集成的组合方式,可快速完成功能定制,而与第三方业务系统的深度融合,能彻底打通“业务下发-设备执行-数据回传-流程闭环”的全链路,让无人机管控真正融入行业业务流程。开发过程中,建议优先采用私有版部署保障数据安全,通过中间适配层降低系统耦合度,结合实际业务场景打磨功能,避免过度开发。随着大疆开发者生态的完善,司空2的二次开发能力将持续升级,为更多行业无人机应用提供技术支撑。

2501_93651177的博客 971

1048 Find Coins (25point(s))

1048 Find Coins (25point(s)) Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special requir

佳迪斯的博客 185

微信小程序 - 最新图片组拖拽排序更换位置功能,类似微信朋友圈九宫格图片的拖动排序效果,微信小程序实现九宫格图片拖拽调换位置,小程序详细实现图像拖曳拖动切换位置排序功能(详细示例代码,一键复制开箱即用

微信小程序,wechat,小程序,图片排序,图像排序,九宫格拖拽排序,拖曳,拖动,拖拽,仿微信朋友圈,朋友圈宫格图片排序,微信朋友圈图片拖动排序效果,实现九宫格图片拖拽,图像拖拽排序组件插件,小程序实现拖拽图片切换图片位置,图片拖动互换位置,图像拖拽切换位置,九宫格图片组合拖动排序,交换九宫格图片的位置,小程序上传图片后,如何实现拖拽排序功能,小程序怎么实现图片拖拽排序,微信小程序图片上传,九宫格拖拽组件,选择图片并拖动_微信小程序图片拖拽,微信小程序长按拖拽排序,图像的拖拽移动,多图拖拽排序功能,实现九宫

✅ 精选推荐文章 4454

1048 Find Coins (25 point(s))

题解 题意不难,主要时间限制150ms,所以尽量限制时间复杂度。还好没有限制空间条件很严。所以用下标标记法标记。。。 #include&lt;cstdio&gt; #include&lt;algorithm&gt; #include&lt;vector&gt; using namespace std; const int MAXN = 510; const int MAXM = 1e5 ...

徐伯莱 254

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

1048 Find Coins (25 point(s))

1048 Find Coins (25 point(s)) 1048 Find Coins (25 point(s)) Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. Howe

GitHub:https://github.com/myp020301 141

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

PAT甲级 1048 Find Coins (25point(s))

Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...

Seqlist_base的博客 236

1048 Find Coins (25)(25 point(s))

Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...

学习为主,偶尔扯淡 438

1048 Find Coins (25 point(s)) - C语言 PAT 甲级

设计思路: * 利用数组和数组索引存每个数出现的次数,遍历寻找到第一对符合条件的,即可输出, * 因为遍历过程中,索引从小到大,相当于数值从小到大遍历,可以保证 V1 是最小值

有三只土豆 246

PAT A1048 Find Coins (25point(s))

题目链接 AC代码 #include<cstdio> int hashtable[1000];//hashtable[i]表示数字i出现的次数 int main(){ int n,pay,t; scanf("%d %d",&n,&pay);//输入硬币数和付款金额 for(int i=0;i<n;i++){ scanf("%...

皮皮瓜的博客 143

PAT(甲级)1048 Find Coins (25point(s))

题目 题目链接 思路 题目大意:给一个数组和一个目标值,问数组中是否存在两个数之和等于目标值; 将数组的数进行hash计数,从小到大一个个枚举; 注意:要考虑自身与自身相加等于目标值的情况; 尽管每个数都不会超过500,但是目标值会超过500,此时如果hash数组只开了510,会导致越界; 代码 #include <iostream> #include <string> #include <cstring> #include <vector> #include

hjyp的博客 228

pat 甲级 1048 Find Coins (25 point(s))散列表和二分查找

题意:第一行,n个硬币,要付pay这么多钱 第二行,n个硬币的种类; 取两个数和要为pay的硬币种类;(如果有不同的选择,选第一个是最小的那个,比如pay为15) 有两个方案,2 13和4 11,取2和13; 思路:用hashtable记录硬币的个数,注意点,如果输出硬币种类相同就要对应hashtable>1,如果是测试点1过不去就是因为没有设置硬币的份额要小于pay的前提,如下; 代码: #include<iostream> #include&l...

m0_51711089的博客 339

1048. Find Coins (25)-PAT甲级真题(Hash散列)

1048. Find Coins (25) Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coin

柳婼 の blog 1868

PAT 解题报告 1048. Find Coins (25)

1048. Find Coins (25) Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coin...

weixin_34268843的博客 236

1048 Find Coins (25)(25 point(s)(cj)

1048 Find Coins (25)(25 point(s)) Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all k...

Cute_jinx的博客 357

1048. Find Coins (25)

题目如下: Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payme

最美的时光 1099

1048 Find Coins(25 分)

1048 Find Coins(25 分) Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coin...

galesaur_wcy 570
上一篇: 1096 Consecutive Factors (20 point(s))
下一篇: 1081 Rational Sum (20 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值