CodeForces346 C. Number Transformation II

AgentScope实战训练营:从零搭建一个完整的A2A Agent应用 2024年4月,Google在Google Cloud Next大会上正式提出了A2A(Agent-to-Agent)协议,这是一个开放协议,旨在让不同的AI Agent之间能够像微服务一样相互发现、相互调用。通俗地讲:A2A协议就是AI Agent世界的HTTP协议——有了它,一个Agent可以把自己的能力以标准化的方式暴露出去,另一个Agent可以无缝地发现并调用它。本文将基于阿里巴巴开源的(Apache 2.0协议),手把手带你从零搭建一个完整的A2A Agent应用。 阅读详情

C. Number Transformation II
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a sequence of positive integers x1, x2, ..., xn and two non-negative integers a and b. Your task is to transform a into b. To do that, you can perform the following moves:

  • subtract 1 from the current a;
  • subtract a mod xi (1 ≤ i ≤ n) from the current a.

Operation a mod xi means taking the remainder after division of number a by number xi.

Now you want to know the minimum number of moves needed to transform a into b.

Input

The first line contains a single integer n (1 ≤  n ≤ 105). The second line contains n space-separated integers x1, x2, ..., xn(2 ≤  xi ≤ 109). The third line contains two integers a and b (0  ≤ b ≤  a ≤ 109, a - b ≤ 106).

Output

Print a single integer — the required minimum number of moves needed to transform number a into number b.

Examples
input
3
3 4 5
30 17
output
6
input
3
5 6 7
1000 200
output
206



/*
CodeForces346  C. Number Transformation II

给你两个数a,b
1.每次对于当前的a减去1
2.每次对于当前的a减去 a%(ta[i])

求最少多少次能得到b
类似于贪心,每次减去尽可能多的值。但是一直TLE- -.   后来可以发现a~a-a%ta[i]的所有值
如果减去a%ta[i],都会等于同一个值。  如果当a-a%ta[i] < b时,ta[i]可以说在后面的
搜索就没有作用了.于是乎把ta[i]除去.

hhh-2016-04-16 17:15:20
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
#define lson  (i<<1)
#define rson  ((i<<1)|1)
typedef long long ll;
const int mod = 1000000009;
const int maxn = 100040;
int ta[maxn];
int main()
{
    int n;
    while( scanf("%d",&n) != EOF)
    {
        int num = 0;
        int a,b;
        for(int i =0; i < n; i++)
        {
            scanf("%d",&ta[i]);
        }
        sort(ta,ta+n);
        n = unique(ta,ta+n)-ta;
        scanf("%d%d",&a,&b);
        while(a > b)
        {
            int cur = a - 1;
            for(int i =n-1; i >= 0; i--)
            {
                if(a-a%ta[i] >= b)
                    cur = min(a-a%ta[i],cur);
            }
            a = cur;
            num ++;
            if(a == b) break;
            while(n)
            {
                if(a-a%ta[n-1] < b)
                    n--;
                else
                    break;
            }
        }
        printf("%d\n",num);
    }
    return 0;
}


IP-Guard分类管理详解 大家都知道在配置IPGUARD策略前需要做分类库进行设置和分类。 1、应用程序:可以分类,例如上班时间只能用OFFICE和WPS,记事本等办公软件,可以在分类里设置一个类 ;办公软件,在未分类里找到OFFICE,WPS等拖入心建的分类里就可以在配置策略里调用。 2、网站分类也不一样,可以按照自己方式自定义。也可以导入厂家已经收集到的网站分类。 3、邮箱分类:可以提前定义好一个或... 阅读详情

相关推荐

EVE-NG 新增 qcow2 镜像教程

本文介绍了如何在 EVE-NG 网络仿真平台中添加 QCOW2 镜像并配置 YML 文件。首先,用户需要了解 EVE-NG 的目录结构,上传并重命名 QCOW2 镜像,然后设置文件权限并刷新界面以识别设备。接着,讲解了 YML 文件的作用,它用于定义设备的CPU、内存、网卡等参数,并给出了配置示例。若有多个设备版本,可以通过复制并重命名 YML 文件使其独立显示。最后,通过检查 QEMU 进程和日志验证 YML 配置是否生效。总结部分强调了 EVE-NG 的自动识别机制以及独立管理设备版本的方式。

qq_41862216的博客 3075

codeforces346e

题解: 转载于:https://www.cnblogs.com/yinwuxiao/p/10163587.html

weixin_30783913的博客 185

Carsim2019与Simulink (Matlab2018b)联合仿真成功(超详细)

Carsim与Simulink联合仿真成功

强强的博客 3万+

Codeforces 346C Number Transformation II 构造

题目链接:点击打开链接 = = 990+ms卡过 #include #include #include #include #include #include using namespace std; #define N 100010 #define L(x) (x<<1) #define R(x) (x<<1|1) #define ll int ll n,m,k,a,b; ll x[N]; b

九野的博客 1352

Matcap与菲涅尔

菲尼尔效果(简化版公式):fresnel = base + scale*((1-v*n)^power)透明队列为后前渲染,不关闭深度写入则会覆盖之前的像素,导致混合不了。y的值为0~1,根据x3返回对应y值。两色混合做个demo看看!混合为什么要关闭深度写入?

weixin_62773441的博客 371

瑞萨RH850/U2A8以太网模块mcal说明

如下所有功能的支持需要在达芬奇中开启EthGlobalTimeSupport。秒[32bit], 纳秒[32bit], 纳秒小数[20bit]每一帧发送数据的相关结构缓冲区都放在变量。每一帧接收数据的相关结构缓冲区都放在变量。

至道无难,唯嫌拣择。 1859

codeforces Number Transformation II

codeforces Number Transformation II

wo_der的博客 602

YOLOv8人工智能与深度学习——强化学习

本文介绍了将YOLOv8目标检测模型与强化学习结合的方法。主要应用包括自适应目标检测(动态调整检测参数)、主动学习(智能选择标注样本)和多目标跟踪优化。实现方案采用深度Q网络策略,通过定义状态表示、动作空间和奖励函数,使检测系统能根据环境反馈优化性能。该方法具有自适应优化、资源高效、持续改进等优势,能构建更智能的计算机视觉系统。文章详细说明了强化学习环境的构建、策略网络的实现以及训练过程,并提供了代码示例。

u010117029的博客 259

CodeForces - 346C- Number Transformation II(贪心+暴力。。)

CodeForces - 346C- Number Transformation II You are given a sequence of positive integers x1, x2, …, xn and two non-negative integers a and b. Your task is to transform a into b. To do that, you can p...

weixin_43179892的博客 428

2025年11月架构设计师综合知识真题回顾,附参考答案、解析及所涉知识点(二)

本文整理了2025年11月架构设计师考试的16-30题真题及解析,涵盖多个计算机系统知识领域。主要内容包括:Linux绝对路径以根目录开始(A);模块调用下层数量用扇出表示(B);游乐园问题通过集合运算得出10人未游玩(B);磁盘位示图计算为200字节(C);测试用例核心是输入与预期输出(D)。其他题目涉及软件可靠性测试概念(B错)、评价程序准确度排序(真实程序最高,A)、测试阶段顺序(单元→组装→系统,A)、Web服务器压力测试前置步骤(C)、分时系统响应时间影响因素(用户数量多,A)、逆向工程方法(基于

一几文的编程学习笔记。 220

【QT开发教程】Qt的图形用户界面设计模式:MVC/MVP/MVVM

在Qt框架中,图形用户界面(GUI)的设计模式对于提高代码的可维护性、可扩展性和可测试性至关重要。MVC(Model-View-Controller)、MVP(Model-View-Presenter)和MVVM(Model-View-ViewModel)是常见的三种设计模式。本文将详细介绍这三种设计模式在Qt中的应用。

科技改变人类,技术成就未来 1471

Codeforces Round #201 (Div. 1) C. Number Transformation II(思路)

题目地址:http://codeforces.com/problemset/problem/346/C 思路:显然,要使得步数最少,每次应使得a减少尽量多。a=min{ a-1,min{ a-a%A[i] } } 。每次选择符合条件的A[i]值,即使得a-a%A[i]>=b的A[i]值(若此时不符合条件,以后也不会符合(a在不断减小))加入到下次判断,不断重复,知道a==b为止。 #inc

哆啦AC梦的博客 673

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

CodeForces 346C Number Transformation II

Number Transformation II 题解: 对于操作2来说, a - a % x[i] 就会到左边离a最近的x[i]的倍数。 也就是说 [ k * x[i] + 1, (k+1)* x[i] -1 ]这段区间的的数都会走到 k * x[i]上。 所以对于每个位置都先计算出他到右边最远的覆盖位置。 然后在反着求出每个位置能往左走走到的最远的位置。 代码: ...

dengpangbu3703的博客 215

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

codeforces 346C Number Transformation II

传送门 题意: 给两个数字a,b,有两个操作,第一个操作直接-1,第二个操作是,求a变成b的最少操作数 题解: 很明显令表示由b+k到b的最少操作数,假设b,b+k可以一步操作到达, 由此得出单调上升,即可贪心每次减去最大值 注意:到会有重复,需要用到函数 去重后的数字 当然也有别的思路:考虑到这是第一步可达区间,再从这里可以依次扩展到其他步的可达区间,有机会再写吧 代码: ...

萌萌哒的Leo 294

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Codeforces 346C Number Transformation II 贪心(复杂度计算)

题意及思路:https://www.cnblogs.com/liuzhanshan/p/6560499.html 这个做法的复杂度看似是O(n ^ 2),实际上均摊是O(n)的。我们考虑两种极端数据:一种是全是2,那么去重后实际上只有一个数。这样是O(n)的。另一种是所有的数都不一样,那么为了让最大的那个最小,数分别为2, 3 ...1e5, 1e5 + 1, 但是a和b之差最多只有1e6,这种...

weixin_30808253的博客 228

Number Transformation II(Codeforces Round #201 (Div. 2))

题目链接:http://codeforces.com/contest/347/problem/E You are given a sequence of positive integersx1, x2, ..., xnand two non-negative integersaandb. Your task is to transformaintob. To do that, yo...

weixin_43870697的博客 213

Number Transformation II CodeForces - 347E

题意:求最小步骤从A到B;每一次操作可-1或者a-a%(xi); 贪心,每次都减去最大的; 然后发现暴力肯定会TLE 所以用set存储x数组,直接去重加排序;然后每次操作之后,选择不合法的删去#include<bits/stdc++.h> using namespace std; #define maxn 111111 set<int> st1,st2; int main() { in

曹讽 346

Codeforces Round #346 (Div. 2) E (dfs)

http://codeforces.com/contest/659/problem/E 题意:给出一个无向图,现在让你确定每条边的方向,使得入度为0的点最少。 这个无向图中由几个连通块(其中任何一点都可以到达其他任何一点)组成。接下来理解的过程中,应该想象一下该连通块的样子。用dfs扩展连通块,在这个过程中,一般来说扩展的方向就是边的方向,可以发现只有起点的入度为0。但是如果出

Muya 368

Difference Row

题目: Description You want to arrange n integers a1, a2, ..., an in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. Mor

Orz 391

2020牛客暑期多校训练营(第三场)E.Two Matchings

2020牛客暑期多校训练营(第三场)E.Two Matchings 题目链接 题目描述 A permutation of length n is an array p=[p1,p2,…,pn]p=[p_1, p_2, \ldots, p_n]p=[p1​,p2​,…,pn​], which contains every integer from 1 to n (inclusive) and each number appears exactly once. For example, p=[3,1,4,6,2

旺崽的博客 2675

Gym_100971G_Repair

Alex is repairing his country house. He has a rectangular metal sheet of size a × b. He has to cut two rectangular sheets of sizes a1 × b1 and a2 × b2 from it. All cuts must be parallel to the sides

no2015214099的博客 497

codeforces 920 C Swap Adjacent Elements

Description You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array. For some indices i (1 ≤ i ≤ n - 1) it is possible to swap ith" role="presentati

toby的博客 521

【ICPC PACIFIC NORTHWEST REGION】 B.Perfect Flush 单调栈

You are given a list of integers x1, x2, . . . , xn and a number k. It is guaranteed that each i from 1 to k appears in the list at least once. Find the lexicographically smallest subsequence of x that contains each integer from 1 to k exactly once. Input

待到山花烂漫时 381

Codeforces Round #201 (Div. 2)

A. Difference Row time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You want to arrange n integers a1, a2, ..

野生的声威的专栏 1098
上一篇: hdu 3436 线段树 一顿操作
下一篇: 南京理工大学第八届程序设计大赛(校外镜像)
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值