BZOJ 4029 [HEOI 4029] 定价 解题报告
2015-05-02 11:41
369 查看
这个题好像也是贪心的感觉。。
我们枚举 $1,5,10,50,100,\dots$ ,找出在 $[l, r]$ 内能整除它们的最小的数。
然后找到其中在荒谬值最小的情况下数值最小的那个数,
就做完了。
4029_Gromah
我们枚举 $1,5,10,50,100,\dots$ ,找出在 $[l, r]$ 内能整除它们的最小的数。
然后找到其中在荒谬值最小的情况下数值最小的那个数,
就做完了。
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; #define INF 593119681 int _; LL l, r; inline LL Calc(LL x) { if (!~x) return INF; while (x % 10 == 0) x /= 10; int f = (x % 5) ? 0 : -1; int res = 0; for (; x; x /= 10) res += 2; return res + f; } int main() { #ifndef ONLINE_JUDGE freopen("4029.in", "r", stdin); freopen("4029.out", "w", stdout); #endif for (scanf("%d", &_); _; _ --) { scanf("%lld%lld", &l, &r); LL best = -1, top, bot; for (LL x = 1, _x = 5; x <= r; x *= 10, _x *= 10) { top = (l + x - 1) / x * x; bot = r / x * x; if (top <= bot) best = (Calc(best) < Calc(top) || (Calc(best) == Calc(top) && best < top)) ? best : top; top = (l + _x - 1) / _x * _x; bot = r / _x * _x; if (top <= bot) best = (Calc(best) < Calc(top) || (Calc(best) == Calc(top) && best < top)) ? best : top; } printf("%lld\n", best); } #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
4029_Gromah
相关文章推荐
- [HEOI2005]BZOJ 4029定价 - 贪心
- [HEOI2015]定价 解题报告
- bzoj4029: [HEOI2015]定价
- 【BZOJ4029】【HEOI2015】定价 模拟
- [BZOJ4029][HEOI2015]定价
- BZOJ4029 4029: [HEOI2015]定价 贪心
- BZOJ 4029: [HEOI2015]定价
- BZOJ 4029: [HEOI2015]定价|贪心|模拟
- BZOJ 4029 HEOI2015 定价 数位贪心
- BZOJ 4027 [HEOI 2015] 兔子与樱花 解题报告
- BZOJ4029 HEOI2015定价
- BZOJ 4029: [HEOI2015]定价 贪心,模拟
- BZOJ 2744 [HEOI 2012] 二分图最大独立集 解题报告
- [BZOJ4029][HEOI2015] 定价
- bzoj4029 [HEOI2015]定价
- BZOJ4029: [HEOI2015]定价
- [bzoj 4029--HEOI2015]定价
- BZOJ 4029: [HEOI2015]定价 贪心
- 【HEOI2015】【BZOJ4029】定价
- bzoj 2748 音量调节 DP 解题报告