构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!
/*
构造:从大到小构造,每一次都把最后不是9的变为9,p - p MOD 10^k - 1,直到小于最小值。
另外,最多len-1次循环
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; typedef long long ll;
const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f; int get_len(ll x) {
int ret = ;
while (x) {
x /= ; ret++;
}
return ret;
} int get_nine(ll x) {
int ret = ;
while (x) {
ll y = x % ; x /= ;
if (y != ) break;
ret++;
}
return ret;
} int main(void) { //Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!
//freopen ("C.in", "r", stdin); ll p, d;
while (scanf ("%I64d%I64d", &p, &d) == ) {
int len = get_len (p); ll now = p;
int mx = get_nine (p); ll ans = p;
ll cut = ;
while (true) {
ll y = now / cut % ;
if (y != ) {
now = now - cut * ; now = now / cut + cut - ;
}
cut *= ;
if (now < p - d) break;
int cnt = get_nine (now);
if (cnt > mx) ans = now;
} printf ("%I64d\n", ans);
} return ;
}
构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!的更多相关文章
- CodeForces 219B Special Offer! Super Price 999 Bourles!
Special Offer! Super Price 999 Bourles! Time Limit:1000MS Memory Limit:262144KB 64bit IO For ...
- Special Offer! Super Price 999 Bourles!
Description Polycarpus is an amateur businessman. Recently he was surprised to find out that the mar ...
- Codeforces Round #135 (Div. 2)
A. k-String 统计每个字母出现次数即可. B. Special Offer! Super Price 999 Bourles! 枚举末尾有几个9,注意不要爆掉\(long\ long\)的范 ...
- 树形DP Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland
题目传送门 /* 题意:求一个点为根节点,使得到其他所有点的距离最短,是有向边,反向的距离+1 树形DP:首先假设1为根节点,自下而上计算dp[1](根节点到其他点的距离),然后再从1开始,自上而下计 ...
- 贪心 Codeforces Round #135 (Div. 2) C. Color Stripe
题目传送门 /* 贪心:当m == 2时,结果肯定是ABABAB或BABABA,取最小改变量:当m > 2时,当与前一个相等时, 改变一个字母 同时不和下一个相等就是最优的解法 */ #incl ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...
随机推荐
- Object-C 打开工程,选择模拟起时,提示"no scheme"
错误提示,如下图: 解决思路:
- POJ——T 2728 Desert King
http://poj.org/problem?id=2728 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27191 ...
- codevs——6220 ZHR吃好吃的
6220 ZHR吃好吃的 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 有一个人名字叫ZHR, ...
- HAProxy+Redis实现负载负载均衡(待实践)
为什么要使用HA,原因是可以聚合出一个VIP,也就是可以使用单一IP来访问下面多个Redis的实例. 首先说明一下,如果基于3.0以后搭建的官方原始Redis Cluster方案,使用HAProxy是 ...
- python dos2unix
有时你在windows上创建的文件拿到Linux/unix上运行会出错, 这是因为windows上有些字符如换行符在linux/unix不识别.这种情况下需要用dos2unix这个工具把文件转换成li ...
- 1.spring boot要求最低jdk1.8,平安默认1.6问题,-》安装JDK1.8 2.maven 3.3.3要求最低jdk1.7->安装jdk 1.8
1.spring boot要求最低jdk1.8,平安默认1.6问题,->安装JDK1.82.maven 3.3.3要求最低jdk1.7->安装jdk 1.8
- Redux 中文文档
http://cn.redux.js.org/docs/introduction/Ecosystem.html
- hibernate之多对一单向关联
一个工作组(Group)里能够有多个用户(User),一个User仅仅属于一个Group,这是典型的多对一的关系. 在多对一的关系中正确的数据库设计是在多的这方(在这里是User这方)加一个Group ...
- Gulp安装及使用
測试环境 Mac:10.10.4 Gulp:3.9.0 时间:2015年08月15日18:07:08 安装Gulp sudo npm install --global gulp npm install ...
- 慎用Outline ,UGUI Outline实现原理分析
使用 UGUI 制作背包的时候.同事发现假设背包中加入了大量的物品.比方两百个.Unity就会出错,提示 Canvas element contains more than 65535 vertice ...