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; }
相关文章推荐
- 好用的jquery分页插件 kkpager
- 数据结构之各种数据结构插入、删除、查找的时间复杂度
- 5.7 区域提取
- c++实现快排出现错误
- LeetCode之双指针(3)
- Android样式之Shape
- Android 的Otto插件的使用
- 选择之后,再返回来还是之前选择的
- Android Handler 四个使用实例 及HandlerThread的使用,androidhandler实例,HandlerThread 源码分析
- !MESSAGE Job found still running after platform shutdown. Jobs should be canceled by the plugin tha
- java开发记录
- Apache+tomcat集群(负载均衡)
- 184,ScrollView中常用的属性与代理方法
- appium安装
- Ubuntu下Android apk反编译
- xd
- Collections之二分查找
- nodejs base64 编码解码
- Python 模拟三级菜单
- 2015年12月全球浏览器份额:IE份额首次跌破50%