当前位置:网站首页>【8.2】代码源 - 【货币系统】【硬币】【新年的问题(数据加强版)】【三段式】
【8.2】代码源 - 【货币系统】【硬币】【新年的问题(数据加强版)】【三段式】
2022-08-05 03:51:00 【ZhgDgE】
#852. 货币系统
题意:给定货币系统。对于某价值,小 t 每次会从钱包里找出不超过还需要支付的金额的最大货币,用于支付,一直到支付完毕。如果对于所有正整数价值,不存在其他支付方案的货币总数严格小于小 t 的支付货币数,那么这个国家是聪明的。 1 ≤ n ≤ 1000 , 1 = a i < a 2 < ⋯ a n ≤ 10000 1\leq n \leq 1000,1=a_i<a_2<\cdots a_n\leq 10000 1≤n≤1000,1=ai<a2<⋯an≤10000
思路:首先有个结论(不会证): ∀ w > 2 × max ( a i ) , w \forall w>2\times \max(a_i),w ∀w>2×max(ai),w 是聪明的。
那么我们只需要判断这个上界之下的数字即可。先暴力计算每个价值小 t 的支付货币数,然后可以用背包求解每个价值的最少货币数,逐一判断是否聪明。把一个面值 a i a_i ai 看作体积为 a i a_i ai ,价值为 1 1 1 的物品,问你恰好装满背包的最少价值,跑一下背包就行。
AC代码:http://oj.daimayuan.top/submission/315376
#815. 硬币
题意:略。
思路:不会,直接抄的题解。
AC代码:http://oj.daimayuan.top/submission/316043
#856. 新年的问题(数据加强版)
题意:给定一个 n × m n×m n×m 的矩阵,要求在每列中恰好选择一个数,并且这些数里面存在两个数在同一行,要求使这 m m m 个数的最小值最大,输出该值。 2 ≤ n , m ≤ 2500 , a i , j ≤ 1 0 9 2\leq n,m\leq 2500,a_{i,j}\leq 10^9 2≤n,m≤2500,ai,j≤109
思路:二分最小值,判断是否有选择方案。判断的话,保留大于等于二分数的元素,如果每一列都有元素,且存在某行有至少两个元素,则存在选择方案。
这里要注意一个和寻址方式有关的常数优化。
我的遍历(400+ms):
rep(j, 1, m) rep(i, 1, n)
if(a[i][j] >= down){
// solve
}
AC代码遍历(220ms):
rep(i, 1, n) rep(j, 1, m)
if(a[i][j] >= down){
// solve
}
数组不管是一维还是高维,在内存里都是连续存放的。后者遍历,绝大多数的寻址都是连续的,因为 cache 的存在,我们都可以根据上一次的地址快速得到。而前者遍历,我们每次寻址在数组里都是跳跃的而不是连续的,取数就会很慢。
AC代码:http://oj.daimayuan.top/submission/316533
#872. 三段式
题意:有一个长度为 n ( 1 ≤ n ≤ 1 0 5 ) n(1\leq n\leq 10^5) n(1≤n≤105) 的序列 a ( ∣ a i ∣ ≤ 1 0 5 ) a(|a_i|\leq 10^5) a(∣ai∣≤105) ,现在我们想把它切割成三段(每一段都是连续的),使得每一段的元素总和都相同,请问有多少种不同的切割方法。
思路:前缀和。设 b a s e = p r e n 3 base=\frac {pre_n} 3 base=3pren ,那么对于每个 p r e i = 2 × b a s e pre_i=2\times base prei=2×base ,看一下前面有多少个 j ( j ∈ [ 1 , i − 1 ] ) j(j\in[1,i-1]) j(j∈[1,i−1]) 满足 p r e j = b a s e pre_j=base prej=base 。注意 i i i 不能枚举到 n n n ,因为是非空。时间复杂度 O ( n log n ) O(n\log n) O(nlogn) 。
边栏推荐
- 达梦8数据库导出导入
- Haproxy搭建Web群集
- 2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer appears after successful startup of presto
- Use Unity to publish APP to Hololens2 without pit tutorial
- Common open source databases under Linux, how many do you know?
- The most effective seven performance testing techniques of software testing techniques
- MRTK3开发Hololens应用-手势拖拽、旋转 、缩放物体实现
- Call Alibaba Cloud oss and sms services
- After the large pixel panorama is completed, what are the promotion methods?
- Defect detection (image processing part)
猜你喜欢
How to wrap markdown - md file
IJCAI2022 | DictBert: Pre-trained Language Models with Contrastive Learning for Dictionary Description Knowledge Augmentation
[Qixi Festival] Romantic Tanabata, code teaser.Turn love into a gorgeous three-dimensional scene and surprise her (him)!(send code)
public static
List asList(T... a) What is the prototype? Dive into how it works together by simulating Vite
Kubernetes 网络入门
UE4 通过互动(键盘按键)开门
UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)
阿里本地生活单季营收106亿,大文娱营收72亿,菜鸟营收121亿
UE4 第一人称角色模板 添加生命值和调试伤害
随机推荐
Acid (ACID) Base (BASE) Principles for Database Design
Walter talked little knowledge | "remote passthrough" that something
AI+PROTAC | dx/tx completes $5 million seed round
leetcode-每日一题1403. 非递增顺序的最小子序列(贪心)
Shell script: for loop and the while loop
UE4 opens door via interaction (keyboard key)
How to solve the three major problems of bank data collection, data supplementary recording and index management?
UE4 第一人称角色模板 添加生命值和调试伤害
JeeSite新建报表
XMjs cross-domain problem solving
[TA-Frost Wolf_may-"Hundred Talents Project"] Graphics 4.3 Real-time Shadow Introduction
静态方法获取配置文件数据
Package zip is not available, but is referred to by another package.
905. 区间选点
10 years of testing experience, worthless in the face of the biological age of 35
从企业的视角来看,数据中台到底意味着什么?
Open-Falcon of operation and maintenance monitoring system
.NET Application -- Helloworld (C#)
多御安全浏览器 V10.8.3.1 版正式发布,优化多项内容
Ffmpeg - sources analysis