首页 > 其他 > 详细

洛谷——P4109 [HEOI2015]定价

时间:2018-10-22 19:13:23      阅读:113      评论:0      收藏:0      [点我收藏+]

P4109 [HEOI2015]定价

 

模拟(有点儿贪心)

 

题目要求在区间$l,r$中$x$后导0尽量多,且除去后导0之外,最后一个数尽量是$5$才最优

从$l$到$r$依次考虑,

假设当前考虑到$5000$,$r=60000$,

那么在$5000$到$6000$之间的都不用考虑,因为比当前优的只能是后导0比其多的(emmm),应该是后导0与其一致或比其多并且符合上述条件的

 

那么每次$l$都要加上$l$这个数的后导0的个数个10

#include<bits/stdc++.h>

using namespace std;

int T,l,r;

int pow(int a,int b){
    int res=1;
    for(;b;b>>=1,a=a*a)
        if(b&1) res=res*a;
    return res;
}

int main()
{
    scanf("%d",&T);
    while(T--){
        int maxn=0x7fffffff;
        scanf("%d%d",&l,&r);
        //->10^N
        int ans;
        while(l<=r){
            int x=l,sum=0,len=0,y;
            while(x) {
                if(!(x%10)) sum++,x/=10;
                else break;
            }
            y=x;
            while(x) x/=10,len++;
            len*=2;
            if(y%10==5) len--;
            if(len<maxn) maxn=len,ans=l;
            l+=pow(10,sum);
        }
        printf("%d\n",ans);
    }
    
    return 0;
}

 

洛谷——P4109 [HEOI2015]定价

原文:https://www.cnblogs.com/song-/p/9831511.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!