BZOJ 4029 HEOI2015 定价 数位贪心
2015-04-29 11:07
253 查看
题目大意:定义一个数的荒谬程度为去掉末尾所有00后的数字数量∗2*2(若末尾为55则荒谬程度减掉11),求[l,r][l,r]区间内荒谬程度最小的数字(若多个相同取最小)
从高位往低位贪心即可。
注意500的荒谬程度比100低
从高位往低位贪心即可。
注意500的荒谬程度比100低
[code]#include <assert.h> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int Calculate(long long l,long long r) { long long temp,ans=0; for(temp=1;temp<=l;temp*=10); if(temp/2>=l&&temp/2<=r) return temp/2; if(temp*5<=r) return temp*5; temp/=10; for(;temp;temp/=10) { long long target; target=l-l%temp+(bool)(l%temp)*temp; if( r>=target ) return ans+target; if(l%temp<=temp/2) { target=l-l%temp+temp/2; if(r>=target) return ans+target; } ans+=l-l%temp; l%=temp;r%=temp; } assert(false); } int main() { //freopen("4029.in","r",stdin); //freopen("4029.out","w",stdout); int T,l,r; for(cin>>T;T;T--) { scanf("%d%d",&l,&r); printf("%d\n",Calculate(l,r)); } return 0; }
相关文章推荐
- BZOJ 4029: [HEOI2015]定价|贪心|模拟
- BZOJ4029 4029: [HEOI2015]定价 贪心
- BZOJ 4029: [HEOI2015]定价 贪心
- BZOJ 4029: [HEOI2015]定价 贪心,模拟
- BZOJ4029 HEOI2015定价
- [bzoj 4029--HEOI2015]定价
- bzoj4029 [HEOI2015]定价
- BZOJ4029: [HEOI2015]定价
- 【HEOI2015】【BZOJ4029】定价
- [HEOI2005]BZOJ 4029定价 - 贪心
- 【BZOJ4029】【HEOI2015】定价 模拟
- 4029: [HEOI2015]定价 贪心
- [BZOJ4029][HEOI2015]定价
- BZOJ 4029: [HEOI2015]定价
- [BZOJ4029][HEOI2015] 定价
- bzoj4029: [HEOI2015]定价
- BZOJ 4029 [HEOI 4029] 定价 解题报告
- bzoj4027 [HEOI2015]兔子与樱花(贪心)
- BZOJ 4027: [HEOI2015]兔子与樱花 贪心
- 【bzoj4027】[HEOI2015]兔子与樱花(树上贪心)