Topic Portal
1 /*2 construction: From large to small structure, each time the last is not 9 into 9,p-p MOD 10^k-1, until less than the minimum value. 3 In addition, up to len-1 cycles4 */5#include <cstdio>6#include <algorithm>7#include <cstring>8#include <cmath>9 using namespacestd;Ten OnetypedefLong Longll; A Const intMAXN = 1e3 +Ten; - Const intINF =0x3f3f3f3f; - the intGet_len (ll x) { - intRET =0; - while(x) { -X/=Ten; ret++; + } - returnret; + } A at intGet_nine (ll x) { - intRET =0; - while(x) { -ll y = x%Ten; X/=Ten; - if(Y! =9) Break; -ret++; in } - returnret; to } + - intMainvoid) {//codeforces Round #135 (Div. 2) B. Special offer! Super Price 999 bourles! the //freopen ("c.in", "R", stdin); * $ ll P, D;Panax Notoginseng while(SCANF ("%i64d%i64d", &p, &d) = =2) { - intlen = Get_len (p); ll now =p; the intmx = Get_nine (p); ll ans =p; +ll cut =1; A while(true) { thell y = now/cut%Ten; + if(Y! =9) { -now = Now-cut *Ten; now = Now/cut + Cut-1; $ } $Cut *=Ten; - if(Now < p-d) Break; - intCNT =Get_nine (now); the if(cnt > mx) ans =Now ; - }Wuyi theprintf ("%i64d\n", ans); - } Wu - return 0; About}
Constructs Codeforces Round #135 (Div. 2) B. Special offer! Super Price 999 bourles!