题目链接:点击打开链接

= = 990+ms卡过

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
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];
bool cmp(ll z,ll y){return z>y;}
set<int>myset;
set<int>::iterator p;
int main(){
ll i,j;
while(cin>>n){
myset.clear();
for(i=1;i<=n;i++)scanf("%d",&j),myset.insert(j);
cin>>a>>b;
if(a==b){puts("0");continue;}
n = myset.size();
i = 1;
for(p = myset.begin(); p!=myset.end(); p++,i++)x[i] = *p;
sort(x+1,x+1+n,cmp);
ll step = 0;
ll l = 1;
while(x[l]>a && l<=n)l++;
while(x[l]>(a>>1) && (a-x[l])>(a-b))l++;
if(l>n){cout<<a-b<<endl;continue;} while(a!=b){
step++;
ll now = 1, cha = a-b; for(i = l;i<=n;i++)
{
if(now>=x[i])break;
ll tmp = a-((a/x[i])*x[i]);
if(tmp<=now || tmp>cha)continue;
now = tmp;
}
a-=now;
while(x[l]>a&&l<=n)l++;
while(x[l]>(a>>1) && (a-x[l])>cha)l++;
if(l>n)break;
}
cout<<step+a-b<<endl;
}
return 0;
}

Codeforces 346C Number Transformation II 构造的更多相关文章

  1. CodeForces 346C Number Transformation II

    Number Transformation II 题解: 对于操作2来说, a - a % x[i] 就会到左边离a最近的x[i]的倍数. 也就是说 [ k * x[i] + 1,  (k+1)* x ...

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

    题意及思路:https://www.cnblogs.com/liuzhanshan/p/6560499.html 这个做法的复杂度看似是O(n ^ 2),实际上均摊是O(n)的.我们考虑两种极端数据: ...

  3. CodeForces346 C. Number Transformation II

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

  4. Codeforces 251C Number Transformation

    Number Transformation 我们能发现这个东西是以2 - k的lcm作为一个循环节, 然后bfs就好啦. #include<bits/stdc++.h> #define L ...

  5. cf201.div1 Number Transformation II 【贪心】

    1 题目描述: 被给一系列的正整数x1,x2,x3...xn和两个非负整数a和b,通过下面两步操作将a转化为b: 1.对当前的a减1. 2.对当前a减去a % xi (i=1,2...n). 计算a转 ...

  6. CSUOJ 1299 - Number Transformation II 打表预处理水DP

    http://122.207.68.93/OnlineJudge/problem.php?id=1299 第二个样例解释.. 3 6 3->4->6..两步.. 由此可以BFS也可以DP. ...

  7. Codeforces 251C Number Transformation DP, 记忆化搜索,LCM,广搜

    题意及思路:https://blog.csdn.net/bossup/article/details/37076965 代码: #include <bits/stdc++.h> #defi ...

  8. codeforces 1059C. Sequence Transformation【构造】

    题目:戳这里 题意:有1,2,3...n这n个数,求一次这些数的gcd,删去一个数,直到剩下一个数为止.输出这n个gcd的最大字典序. 解题思路:一开始的gcd肯定是1,要让字典序最大,我们可以想到下 ...

  9. 2016级算法第二次上机-F.ModricWang's Number Theory II

    891 ModricWang's Number Theory II 思路 使得序列的最大公约数不为1,就是大于等于2,就是找到一个大于等于2的数,它能够整除序列中的所有数. 考虑使得一个数d整除数组中 ...

随机推荐

  1. 【10_169】Majority Element

    今天遇到的题都挺难的,不容易有会做的. 下面是代码,等明天看看Discuss里面有没有简单的方法~ Majority Element My Submissions Question Total Acc ...

  2. Linux内核分析之扒开系统调用的三层皮(上)

    一.原理总结 本周老师讲的内容主要包括三个方面,用户态.内核态和中断,系统调用概述,以及使用库函数API获取系统当前时间.系统调用是操作系统为用户态进程与硬件设备进行交互提供的一组接口,也是一种特殊的 ...

  3. delphi 生成网卡MAC地址

    生成MAC地址的小工具: {*------------------------------------------------ 生成mac地址 @author @version 2015.7.2 20 ...

  4. mysql 授权

    cd /usr/local/mysql/bin/grant all privileges on *.* to 'root'@'%' identified by '12345678';flush pri ...

  5. Magicodes.WeiChat——多租户的设计与实现

    概要 多租户(Multi Tenancy/Tenant)是一种软件架构,其定义是:在一台服务器上运行单个应用实例,它为多个租户提供服务. 本框架使用的是共享数据库.共享 Schema.共享数据表的数据 ...

  6. node-webkit教程(9)native api 之Tray(托盘)

    node-webkit教程(9)native api 之Tray(托盘) 文/玄魂 目录 node-webkit教程(9)native api 之Tray(托盘) 前言 9.1  Tray简介 9.2 ...

  7. [ACM_数学] Counting Solutions to an Integral Equation (x+2y+2z=n 组合种类)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E 题目大意:Given, n, count the numbe ...

  8. paip.php 与js 的相似性以及为什么它们这么烂还很流行。。

    paip.php 与js 的相似性以及为什么它们这么烂还很流行.. php与js异常的流行,web 90%都被他们统治了.发现了他们有意思的一些共性.. 结构一番总结,得出了它们共有的特点.特性: = ...

  9. Leetcode-203 Remove Linked List Elements

    #203.   Remove Linked List Elements Remove all elements from a linked list of integers that have val ...

  10. shell 时间统计脚本

    #!/bin/sh #Today=`date +%Y%m%d` YEAR=`echo $|cut -c -` MONTH=`echo $|cut -c -` DAY=`echo $|cut -c -` ...