Codeforces 346C Number Transformation II 构造
2014-06-21 18:28
316 查看
题目链接:点击打开链接
= = 990+ms卡过
= = 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 ; 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 - 848A From Y to Y(构造)
- Codeforces 804E The same permutation(构造)
- CodeForces 707C Pythagorean Triples(数学 构造)
- codeforces 468A 24 Game 构造
- 【Codeforces 141 B Hopscotch 】+ 构造
- CodeForces 297C Splitting the Uniqueness (脑补构造题)
- CodeForces 123A 构造 + YY
- Codeforces - 715B. Complete The Graph - 构造最短路
- Codeforces 284C Cows and sequence 构造 or 线段树
- codeforces -891B Gluttony 排列,构造题
- Codeforces 827B. High Load 【构造】
- CodeForces 828C【构造】
- Codeforces 246A Buggy Sorting 【构造】
- [随机化 构造] Codeforces 717H Bubble Cup 9 - Finals H. Pokermon League challenge
- Codeforces 398C Tree and Array 构造
- Codeforces 398C Tree and Array(构造)
- CodeForces 9C -Hexadecimal's Numbers-构造
- CodeForces - 148C Terse princess (构造)
- CodeForces 916C Jamie and Interesting Graph (构造)
- codeforces 725C Hidden word(构造)