• Codeforces 346C Number Transformation II 构造


    题目链接:点击打开链接

    = = 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;
    }


  • 相关阅读:
    vue基础指令了解
    django中间件和auth模块
    form组件及cookie和session
    ajax学习相关
    数据库优化查询相关
    Django ORM必会13条之外的查询方法
    Django ORM单表查询必会13条
    Django学习之路05
    Django学习之路04
    Django学习之路03
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5425148.html
Copyright © 2020-2023  润新知