【BZOJ4029】【HEOI2015】定價 類比,bzoj4029heoi2015

來源:互聯網
上載者:User

【BZOJ4029】【HEOI2015】定價 類比,bzoj4029heoi2015
連結:

#include <stdio.h>int main(){    puts("轉載請註明出處[vmurder]謝謝");    puts("網址:blog.csdn.net/vmurder/article/details/45334857");}
題解:

枚舉後面有幾個 0,然後每次(當前求 k 個後導 0 )算出第一個比 L 大的 10k 的倍數,和第一個比 L 大的 5×10k 的倍數。
然後把所有這些數都比較一下就好啦。

代碼:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define inf 0x3f3f3f3fusing namespace std;long long ans,A,B,x;void dfs(long long div){    long long C=((A-1)/div+1)*div,c=0;    if(C>B)return ;    long long D=((A-1)/(5*div)+1)*(5*div),d=0;    if(D>B)d=inf;    for(long long T=C/div;T;T/=10)c+=2;    for(long long T=D/div;T;T/=10)d+=2;        d--;    if(c<=d)    {        if(x>c)        {            x=c;            ans=C;        }    }    else {        if(x>d)        {            x=d;            ans=D;        }    }    dfs(div*10);}int main(){    int i,j,k,g;    for(scanf("%d",&g);g--;)    {        cin>>A>>B;        x=inf,dfs(1);        cout<<ans<<endl;    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.