Luogu P4109 [HEOI2015]定价 贪心
2024-09-02 01:40:01
思路:找规律?$or$贪心。
提交:1次
题解:
发现:若可以构成$X0000$,答案绝对不会再在数字最后把$0$改成其他数;
若可以构成$XX50...0$更优。
所以左端点增加的步长是增加的($inc=pow(10,x),x$递增)。
所以去掉了一些不必要的枚举。
#include<cstdio>
#include<iostream>
#include<cmath>
#define R register int
using namespace std;
#define ull unsigned long long
#define ll long long
#define pause (for(R i=1;i<=10000000000;++i))
#define In freopen("NOIPAK++.in","r",stdin)
#define Out freopen("out.out","w",stdout)
namespace Fread {
static char B[<<],*S=B,*D=B;
#ifndef JACK
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
#endif
inline int g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
if(ch==EOF) return EOF; do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
} inline bool isempty(const char& ch) {return (ch<=||ch>=);}
inline void gs(char* s) {
register char ch; while(isempty(ch=getchar()));
do *s++=ch; while(!isempty(ch=getchar()));
}
} using Fread::g; using Fread::gs;
namespace Luitaryi {
int T,l,r; ll ans;
const ll Inf=1E+;
inline void main() {
T=g(); while(T--) { R mn=Inf;
l=g(),r=g();
while(l<=r) {
R x=l,cnt=;
while(x%==) x/=,++cnt;
R y=x,len=,lst=x%;
while(y) y/=,++len;
R tmp=*len-(lst==);
if(mn>tmp) mn=tmp,ans=l;
l+=pow(,cnt);
} printf("%lld\n",ans);
}
}
}
signed main() {
Luitaryi::main(); return ;
}
最新文章
- error-2015-9-9
- Android 5.x特性概览五
- Android中解析XML
- MySQL数据库学习笔记(六)----MySQL多表查询之外键、表连接、子查询、索引
- 个人介绍和GitHub
- Redis系列-存储篇string主要操作函数小结
- ado模版不会自动生成
- hdu 4752
- iOS 中 Touch ID得使用方法
- Ceph RBD CephFS 存储
- 安装好的虚拟机,外部通过ssh工具连接,报connection failed
- Call to undefined function mysql_connect()错误原因
- Mycat 分片规则详解--ASCII 取模范围分片
- LeetCode算法题-Relative Ranks(Java实现)
- scrapy爬虫之断点续爬和多个spider同时爬取
- python装饰器(备忘)
- docker应用-5(使用overlay 网络进行容器间跨物理主机通信)
- MUI学习01-顶部导航栏
- otter使用
- Jenkins自动化部署代码