您的位置:首页 > 其它

4029: [HEOI2015]定价 贪心

2016-01-08 10:33 246 查看
这个真是怎么贪心都能过了(然而我太弱了还是挂了好几遍)

[code]#include<bits/stdc++.h>
using namespace std;
int L,R,T,mn,ans;
inline int read()
{
    int a=0,f=1; char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
    while (c>='0'&&c<='9') {a=a*10+c-'0'; c=getchar();}
    return a*f;
}
int add(int x)
{
    int k=1;
    while (x%10==0) k*=10,x/=10;
    return k;
}
int calc(int x)
{
    while (x%10==0) x/=10;
    int t=x%10,a=0;
    while (x) x/=10,a++;
    if (t==5) return 2*a-1; return 2*a;
}
int main()
{
    T=read();
    while (T--)
    {
        L=read(),R=read();
        mn=calc(L); ans=L;
        while (1)
        {
            L+=add(L);
            if (L>R) break;
            int t=calc(L);
            if (t<mn) mn=t,ans=L;
        }
        printf("%d\n",ans);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: